Title: [124121] trunk
Revision
124121
Author
[email protected]
Date
2012-07-30 17:24:36 -0700 (Mon, 30 Jul 2012)

Log Message

Add ability to load from a string to the ObjC WK API
https://bugs.webkit.org/show_bug.cgi?id=92590

Reviewed by Dan Bernstein.

Source/WebKit2:

This adds an often used method to the new Objective-C API and will
be helpful for writing API tests.

* UIProcess/API/mac/WKBrowsingContextController.h:
* UIProcess/API/mac/WKBrowsingContextController.mm:
(-[WKBrowsingContextController loadHTMLString:baseURL:]):
Implement via calling down to WKPageLoadHTMLString.

Tools:

Add tests for [WKBrowsingContextController loadHTMLString:baseURL:]. We will be able
to greatly improve these tests (to test more than just not crashing) when methods to
access page content are added (soon!).

Adds:
    Test: WKBrowsingContextLoadDelegateTest_SimpleLoadOfHTMLString
    Test: WKBrowsingContextLoadDelegateTest_SimpleLoadOfHTMLString_NilBaseURL
    Test: WKBrowsingContextLoadDelegateTest_SimpleLoadOfHTMLString_NilHTMLStringAndBaseURL

* TestWebKitAPI/Tests/WebKit2ObjC/WKBrowsingContextLoadDelegateTest.mm:
Adds tests and refactors delegates to not use global state.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (124120 => 124121)


--- trunk/Source/WebKit2/ChangeLog	2012-07-31 00:20:28 UTC (rev 124120)
+++ trunk/Source/WebKit2/ChangeLog	2012-07-31 00:24:36 UTC (rev 124121)
@@ -1,3 +1,18 @@
+2012-07-28  Sam Weinig  <[email protected]>
+
+        Add ability to load from a string to the ObjC WK API
+        https://bugs.webkit.org/show_bug.cgi?id=92590
+
+        Reviewed by Dan Bernstein.
+
+        This adds an often used method to the new Objective-C API and will
+        be helpful for writing API tests.
+
+        * UIProcess/API/mac/WKBrowsingContextController.h:
+        * UIProcess/API/mac/WKBrowsingContextController.mm:
+        (-[WKBrowsingContextController loadHTMLString:baseURL:]):
+        Implement via calling down to WKPageLoadHTMLString.
+
 2012-07-30  Rafael Brandao  <[email protected]>
 
         [WK2] Kill the concept of secondary shared process

Modified: trunk/Source/WebKit2/UIProcess/API/mac/WKBrowsingContextController.h (124120 => 124121)


--- trunk/Source/WebKit2/UIProcess/API/mac/WKBrowsingContextController.h	2012-07-31 00:20:28 UTC (rev 124120)
+++ trunk/Source/WebKit2/UIProcess/API/mac/WKBrowsingContextController.h	2012-07-31 00:24:36 UTC (rev 124121)
@@ -53,6 +53,9 @@
 */
 - (void)loadFileURL:(NSURL *)URL restrictToFilesWithin:(NSURL *)allowedDirectory;
 
+/* Load a page using the passed in string as its contents. */
+- (void)loadHTMLString:(NSString *)HTMLString baseURL:(NSURL *)baseURL;
+
 /* Stops the load associated with the active URL. */
 - (void)stopLoading;
 

Modified: trunk/Source/WebKit2/UIProcess/API/mac/WKBrowsingContextController.mm (124120 => 124121)


--- trunk/Source/WebKit2/UIProcess/API/mac/WKBrowsingContextController.mm	2012-07-31 00:20:28 UTC (rev 124120)
+++ trunk/Source/WebKit2/UIProcess/API/mac/WKBrowsingContextController.mm	2012-07-31 00:24:36 UTC (rev 124121)
@@ -120,6 +120,19 @@
     WKPageLoadURL(self._pageRef, wkURL.get());
 }
 
+- (void)loadHTMLString:(NSString *)HTMLString baseURL:(NSURL *)baseURL
+{
+    WKRetainPtr<WKStringRef> wkHTMLString;
+    if (HTMLString)
+        wkHTMLString = adoptWK(WKStringCreateWithCFString((CFStringRef)HTMLString));
+
+    WKRetainPtr<WKURLRef> wkBaseURL;
+    if (baseURL)
+        wkBaseURL = adoptWK(WKURLCreateWithCFURL((CFURLRef)baseURL));
+
+    WKPageLoadHTMLString(self._pageRef, wkHTMLString.get(), wkBaseURL.get());
+}
+
 - (void)stopLoading
 {
     WKPageStopLoading(self._pageRef);

Modified: trunk/Tools/ChangeLog (124120 => 124121)


--- trunk/Tools/ChangeLog	2012-07-31 00:20:28 UTC (rev 124120)
+++ trunk/Tools/ChangeLog	2012-07-31 00:24:36 UTC (rev 124121)
@@ -1,3 +1,22 @@
+2012-07-28  Sam Weinig  <[email protected]>
+
+        Add ability to load from a string to the ObjC WK API
+        https://bugs.webkit.org/show_bug.cgi?id=92590
+
+        Reviewed by Dan Bernstein.
+
+        Add tests for [WKBrowsingContextController loadHTMLString:baseURL:]. We will be able
+        to greatly improve these tests (to test more than just not crashing) when methods to
+        access page content are added (soon!).
+
+        Adds:
+            Test: WKBrowsingContextLoadDelegateTest_SimpleLoadOfHTMLString
+            Test: WKBrowsingContextLoadDelegateTest_SimpleLoadOfHTMLString_NilBaseURL
+            Test: WKBrowsingContextLoadDelegateTest_SimpleLoadOfHTMLString_NilHTMLStringAndBaseURL
+
+        * TestWebKitAPI/Tests/WebKit2ObjC/WKBrowsingContextLoadDelegateTest.mm:
+        Adds tests and refactors delegates to not use global state.
+
 2012-07-30  Thiago Marcos P. Santos  <[email protected]>
 
         [CMake] TestWebKitAPI bundle should link with WTF

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2ObjC/WKBrowsingContextLoadDelegateTest.mm (124120 => 124121)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2ObjC/WKBrowsingContextLoadDelegateTest.mm	2012-07-31 00:20:28 UTC (rev 124120)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2ObjC/WKBrowsingContextLoadDelegateTest.mm	2012-07-31 00:24:36 UTC (rev 124121)
@@ -35,6 +35,8 @@
 
 #import "PlatformUtilities.h"
 
+namespace {
+
 class WKBrowsingContextLoadDelegateTest : public ::testing::Test { 
 public:
     WKProcessGroup *processGroup;
@@ -63,17 +65,32 @@
     }
 };
 
+} // namespace
 
-static bool simpleLoadDone;
+@interface SimpleLoadDelegate : NSObject <WKBrowsingContextLoadDelegate>
+{
+    bool* _simpleLoadDone;
+}
 
-@interface SimpleLoadDelegate : NSObject <WKBrowsingContextLoadDelegate>
+- (id)initWithFlag:(bool*)flag;
+
 @end
 
 @implementation SimpleLoadDelegate
 
+- (id)initWithFlag:(bool*)flag
+{
+    self = [super init];
+    if (!self)
+        return nil;
+
+    _simpleLoadDone = flag;
+    return self;
+}
+
 - (void)browsingContextControllerDidFinishLoad:(WKBrowsingContextController *)sender
 {
-    simpleLoadDone = true;
+    *_simpleLoadDone = true;
 }
 
 @end
@@ -85,8 +102,10 @@
 
 TEST_F(WKBrowsingContextLoadDelegateTest, SimpleLoad)
 {
+    bool simpleLoadDone = false;
+
     // Add the load delegate.
-    SimpleLoadDelegate *loadDelegate = [[SimpleLoadDelegate alloc] init];
+    SimpleLoadDelegate *loadDelegate = [[SimpleLoadDelegate alloc] initWithFlag:&simpleLoadDone];
     view.browsingContextController.loadDelegate = loadDelegate;
 
     // Load the file.
@@ -101,28 +120,100 @@
     [loadDelegate release];
 }
 
+TEST_F(WKBrowsingContextLoadDelegateTest, SimpleLoadOfHTMLString)
+{
+    bool simpleLoadDone = false;
 
-static bool simpleLoadFailDone;
+    // Add the load delegate.
+    SimpleLoadDelegate *loadDelegate = [[SimpleLoadDelegate alloc] initWithFlag:&simpleLoadDone];
+    view.browsingContextController.loadDelegate = loadDelegate;
 
+    // Load the HTML string.
+    [view.browsingContextController loadHTMLString:@"<html><body>Simple HTML String</body></html>" baseURL:[NSURL URLWithString:@"about:blank"]];
+
+    // Wait for the load to finish.
+    TestWebKitAPI::Util::run(&simpleLoadDone);
+
+    // Tear down the delegate.
+    view.browsingContextController.loadDelegate = nil;
+    [loadDelegate release];
+}
+
+TEST_F(WKBrowsingContextLoadDelegateTest, SimpleLoadOfHTMLString_NilBaseURL)
+{
+    bool simpleLoadDone = false;
+
+    // Add the load delegate.
+    SimpleLoadDelegate *loadDelegate = [[SimpleLoadDelegate alloc] initWithFlag:&simpleLoadDone];
+    view.browsingContextController.loadDelegate = loadDelegate;
+
+    // Load the HTML string, pass nil as the baseURL.
+    [view.browsingContextController loadHTMLString:@"<html><body>Simple HTML String</body></html>" baseURL:nil];
+
+    // Wait for the load to finish.
+    TestWebKitAPI::Util::run(&simpleLoadDone);
+
+    // Tear down the delegate.
+    view.browsingContextController.loadDelegate = nil;
+    [loadDelegate release];
+}
+
+TEST_F(WKBrowsingContextLoadDelegateTest, SimpleLoadOfHTMLString_NilHTMLStringAndBaseURL)
+{
+    bool simpleLoadDone = false;
+
+    // Add the load delegate.
+    SimpleLoadDelegate *loadDelegate = [[SimpleLoadDelegate alloc] initWithFlag:&simpleLoadDone];
+    view.browsingContextController.loadDelegate = loadDelegate;
+
+    // Load the HTML string (as nil).
+    [view.browsingContextController loadHTMLString:nil baseURL:nil];
+
+    // Wait for the load to finish.
+    TestWebKitAPI::Util::run(&simpleLoadDone);
+
+    // Tear down the delegate.
+    view.browsingContextController.loadDelegate = nil;
+    [loadDelegate release];
+}
+
 @interface SimpleLoadFailDelegate : NSObject <WKBrowsingContextLoadDelegate>
+{
+    bool* _simpleLoadFailDone;
+}
+
+- (id)initWithFlag:(bool*)flag;
+
 @end
 
 @implementation SimpleLoadFailDelegate
 
+- (id)initWithFlag:(bool*)flag
+{
+    self = [super init];
+    if (!self)
+        return nil;
+
+    _simpleLoadFailDone = flag;
+    return self;
+}
+
 - (void)browsingContextControllerDidFailProvisionalLoad:(WKBrowsingContextController *)sender withError:(NSError *)error
 {
     EXPECT_EQ(-1100, error.code);
     EXPECT_WK_STREQ(NSURLErrorDomain, error.domain);
     
-    simpleLoadFailDone = true;
+    *_simpleLoadFailDone = true;
 }
 
 @end
 
 TEST_F(WKBrowsingContextLoadDelegateTest, SimpleLoadFail)
 {
+    bool simpleLoadFailDone = false;
+
     // Add the load delegate.
-    SimpleLoadFailDelegate *loadDelegate = [[SimpleLoadFailDelegate alloc] init];
+    SimpleLoadFailDelegate *loadDelegate = [[SimpleLoadFailDelegate alloc] initWithFlag:&simpleLoadFailDone];
     view.browsingContextController.loadDelegate = loadDelegate;
 
     // Load a non-existent file.
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to