Index: content/browser/service_worker/service_worker_browsertest.cc |
diff --git a/content/browser/service_worker/service_worker_browsertest.cc b/content/browser/service_worker/service_worker_browsertest.cc |
index b833a0ffc3bfabc7d0bc86fccc2d36f5a9e2ddaa..eef8b6ce75dfe8d7be24d87b56ef93b18d3216ad 100644 |
--- a/content/browser/service_worker/service_worker_browsertest.cc |
+++ b/content/browser/service_worker/service_worker_browsertest.cc |
@@ -14,7 +14,6 @@ |
#include "content/browser/service_worker/service_worker_test_utils.h" |
#include "content/browser/service_worker/service_worker_version.h" |
#include "content/common/service_worker/service_worker_messages.h" |
-#include "content/common/service_worker/service_worker_status_code.h" |
#include "content/common/service_worker/service_worker_types.h" |
#include "content/public/browser/browser_context.h" |
#include "content/public/browser/browser_thread.h" |
@@ -22,6 +21,7 @@ |
#include "content/public/browser/storage_partition.h" |
#include "content/public/browser/web_contents.h" |
#include "content/public/common/content_switches.h" |
+#include "content/public/common/service_worker_status_code.h" |
#include "content/shell/browser/shell.h" |
#include "content/test/content_browser_test.h" |
#include "content/test/content_browser_test_utils.h" |
@@ -53,6 +53,20 @@ void RunOnIOThread(const base::Closure& closure) { |
run_loop.Run(); |
} |
+void RunOnIOThread( |
+ const base::Callback<void(const base::Closure& continuation)>& closure) { |
+ base::RunLoop run_loop; |
+ base::Closure quit_on_original_thread = |
+ base::Bind(base::IgnoreResult(&base::MessageLoopProxy::PostTask), |
+ base::MessageLoopProxy::current().get(), |
+ FROM_HERE, |
+ run_loop.QuitClosure()); |
+ BrowserThread::PostTask(BrowserThread::IO, |
+ FROM_HERE, |
+ base::Bind(closure, quit_on_original_thread)); |
+ run_loop.Run(); |
+} |
+ |
// Contrary to the style guide, the output parameter of this function comes |
// before input parameters so Bind can be used on it to create a FetchCallback |
// to pass to DispatchFetchEvent. |
@@ -90,7 +104,8 @@ class ServiceWorkerBrowserTest : public ContentBrowserTest { |
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
StoragePartition* partition = BrowserContext::GetDefaultStoragePartition( |
shell()->web_contents()->GetBrowserContext()); |
- wrapper_ = partition->GetServiceWorkerContext(); |
+ wrapper_ = static_cast<ServiceWorkerContextWrapper*>( |
+ partition->GetServiceWorkerContext()); |
// Navigate to the page to set up a renderer page (where we can embed |
// a worker). |
@@ -110,6 +125,7 @@ class ServiceWorkerBrowserTest : public ContentBrowserTest { |
virtual void TearDownOnIOThread() {} |
ServiceWorkerContextWrapper* wrapper() { return wrapper_.get(); } |
+ ServiceWorkerContext* public_context() { return wrapper(); } |
void AssociateRendererProcessToWorker(EmbeddedWorkerInstance* worker) { |
worker->AddProcessReference( |
@@ -416,4 +432,95 @@ IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, FetchEvent_Rejected) { |
ASSERT_EQ(SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, result); |
} |
+class ServiceWorkerBlackBoxBrowserTest : public ServiceWorkerBrowserTest { |
kinuko
2014/03/26 05:01:34
(Ok to have this for now, but this file's going a
Jeffrey Yasskin
2014/03/26 19:58:52
I agree with separate files. This test seems to be
|
+ public: |
+ typedef ServiceWorkerBlackBoxBrowserTest self; |
+ |
+ static void ExpectStatusAndRun(ServiceWorkerStatusCode expected, |
+ const base::Closure& continuation, |
+ ServiceWorkerStatusCode actual) { |
+ EXPECT_EQ(expected, actual); |
+ continuation.Run(); |
+ } |
+ |
+ int RenderProcessID() { |
+ return shell()->web_contents()->GetRenderProcessHost()->GetID(); |
+ } |
+ |
+ void FindRegistrationOnIO(const GURL& document_url, |
+ ServiceWorkerStatusCode* status, |
+ GURL* script_url, |
+ const base::Closure& continuation) { |
+ wrapper()->context()->storage()->FindRegistrationForDocument( |
+ document_url, |
+ base::Bind(&ServiceWorkerBlackBoxBrowserTest::FindRegistrationOnIO2, |
+ this, |
+ status, |
+ script_url, continuation)); |
+ } |
+ |
+ void FindRegistrationOnIO2( |
+ ServiceWorkerStatusCode* out_status, |
+ GURL* script_url, |
+ const base::Closure& continuation, |
+ ServiceWorkerStatusCode status, |
+ const scoped_refptr<ServiceWorkerRegistration>& registration) { |
+ *out_status = status; |
+ if (registration) { |
+ *script_url = registration->script_url(); |
+ } else { |
+ EXPECT_NE(SERVICE_WORKER_OK, status); |
+ } |
+ continuation.Run(); |
+ } |
+}; |
+ |
+IN_PROC_BROWSER_TEST_F(ServiceWorkerBlackBoxBrowserTest, Registration) { |
+ const std::string kWorkerUrl = "/service_worker/fetch_event.js"; |
+ { |
+ base::RunLoop run_loop; |
+ public_context()->RegisterServiceWorker( |
+ embedded_test_server()->GetURL("/*"), |
+ embedded_test_server()->GetURL(kWorkerUrl), |
+ RenderProcessID(), |
+ base::Bind(&ServiceWorkerBlackBoxBrowserTest::ExpectStatusAndRun, |
+ SERVICE_WORKER_OK, |
+ run_loop.QuitClosure())); |
+ run_loop.Run(); |
+ } |
+ { |
+ ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; |
+ GURL script_url; |
+ RunOnIOThread( |
+ base::Bind(&ServiceWorkerBlackBoxBrowserTest::FindRegistrationOnIO, |
+ this, |
+ embedded_test_server()->GetURL("/service_worker/empty.html"), |
+ &status, |
+ &script_url)); |
+ EXPECT_EQ(SERVICE_WORKER_OK, status); |
+ EXPECT_EQ(embedded_test_server()->GetURL(kWorkerUrl), script_url); |
+ } |
+ { |
+ base::RunLoop run_loop; |
+ public_context()->UnregisterServiceWorker( |
+ embedded_test_server()->GetURL("/*"), |
+ RenderProcessID(), |
+ base::Bind(&ServiceWorkerBlackBoxBrowserTest::ExpectStatusAndRun, |
+ SERVICE_WORKER_OK, |
+ run_loop.QuitClosure())); |
+ run_loop.Run(); |
+ } |
+ { |
+ ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; |
+ GURL script_url; |
+ RunOnIOThread( |
+ base::Bind(&ServiceWorkerBlackBoxBrowserTest::FindRegistrationOnIO, |
+ this, |
+ embedded_test_server()->GetURL("/service_worker/empty.html"), |
+ &status, |
+ &script_url)); |
+ EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, status); |
+ } |
+} |
+ |
} // namespace content |