OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 #include <map> | 7 #include <map> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
35 #include "content/public/browser/content_browser_client.h" | 35 #include "content/public/browser/content_browser_client.h" |
36 #include "content/public/browser/navigation_entry.h" | 36 #include "content/public/browser/navigation_entry.h" |
37 #include "content/public/browser/render_process_host.h" | 37 #include "content/public/browser/render_process_host.h" |
38 #include "content/public/browser/render_view_host.h" | 38 #include "content/public/browser/render_view_host.h" |
39 #include "content/public/browser/storage_partition.h" | 39 #include "content/public/browser/storage_partition.h" |
40 #include "content/public/browser/web_contents.h" | 40 #include "content/public/browser/web_contents.h" |
41 #include "content/public/common/content_client.h" | 41 #include "content/public/common/content_client.h" |
42 #include "content/public/common/content_switches.h" | 42 #include "content/public/common/content_switches.h" |
43 #include "content/public/common/referrer.h" | 43 #include "content/public/common/referrer.h" |
| 44 #include "content/public/common/resource_type.h" |
44 #include "content/public/common/security_style.h" | 45 #include "content/public/common/security_style.h" |
45 #include "content/public/common/ssl_status.h" | 46 #include "content/public/common/ssl_status.h" |
46 #include "content/public/common/web_preferences.h" | 47 #include "content/public/common/web_preferences.h" |
47 #include "content/public/test/browser_test_utils.h" | 48 #include "content/public/test/browser_test_utils.h" |
48 #include "content/public/test/content_browser_test.h" | 49 #include "content/public/test/content_browser_test.h" |
49 #include "content/public/test/content_browser_test_utils.h" | 50 #include "content/public/test/content_browser_test_utils.h" |
50 #include "content/shell/browser/shell.h" | 51 #include "content/shell/browser/shell.h" |
51 #include "content/shell/browser/shell_content_browser_client.h" | 52 #include "content/shell/browser/shell_content_browser_client.h" |
52 #include "content/test/test_content_browser_client.h" | 53 #include "content/test/test_content_browser_client.h" |
53 #include "net/test/embedded_test_server/embedded_test_server.h" | 54 #include "net/test/embedded_test_server/embedded_test_server.h" |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 return make_scoped_ptr(new net::test_server::BasicHttpResponse()); | 220 return make_scoped_ptr(new net::test_server::BasicHttpResponse()); |
220 } | 221 } |
221 | 222 |
222 // The ImportsBustMemcache test requires that the imported script | 223 // The ImportsBustMemcache test requires that the imported script |
223 // would naturally be cached in blink's memcache, but the embedded | 224 // would naturally be cached in blink's memcache, but the embedded |
224 // test server doesn't produce headers that allow the blink's memcache | 225 // test server doesn't produce headers that allow the blink's memcache |
225 // to do that. This interceptor injects headers that give the import | 226 // to do that. This interceptor injects headers that give the import |
226 // an experiration far in the future. | 227 // an experiration far in the future. |
227 class LongLivedResourceInterceptor : public net::URLRequestInterceptor { | 228 class LongLivedResourceInterceptor : public net::URLRequestInterceptor { |
228 public: | 229 public: |
229 LongLivedResourceInterceptor(const std::string& body) | 230 explicit LongLivedResourceInterceptor(const std::string& body) |
230 : body_(body) {} | 231 : body_(body) {} |
231 ~LongLivedResourceInterceptor() override {} | 232 ~LongLivedResourceInterceptor() override {} |
232 | 233 |
233 // net::URLRequestInterceptor implementation | 234 // net::URLRequestInterceptor implementation |
234 net::URLRequestJob* MaybeInterceptRequest( | 235 net::URLRequestJob* MaybeInterceptRequest( |
235 net::URLRequest* request, | 236 net::URLRequest* request, |
236 net::NetworkDelegate* network_delegate) const override { | 237 net::NetworkDelegate* network_delegate) const override { |
237 const char kHeaders[] = | 238 const char kHeaders[] = |
238 "HTTP/1.1 200 OK\n" | 239 "HTTP/1.1 200 OK\n" |
239 "Content-Type: text/javascript\n" | 240 "Content-Type: text/javascript\n" |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 } | 586 } |
586 | 587 |
587 void RemoveLiveRegistrationOnIOThread(int64_t id) { | 588 void RemoveLiveRegistrationOnIOThread(int64_t id) { |
588 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 589 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
589 wrapper()->context()->RemoveLiveRegistration(id); | 590 wrapper()->context()->RemoveLiveRegistration(id); |
590 } | 591 } |
591 | 592 |
592 void StartOnIOThread(const base::Closure& done, | 593 void StartOnIOThread(const base::Closure& done, |
593 ServiceWorkerStatusCode* result) { | 594 ServiceWorkerStatusCode* result) { |
594 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 595 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
595 version_->StartWorker(CreateReceiver(BrowserThread::UI, done, result)); | 596 version_->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN, |
| 597 CreateReceiver(BrowserThread::UI, done, result)); |
596 } | 598 } |
597 | 599 |
598 void InstallOnIOThread(const base::Closure& done, | 600 void InstallOnIOThread(const base::Closure& done, |
599 ServiceWorkerStatusCode* result) { | 601 ServiceWorkerStatusCode* result) { |
600 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 602 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
601 version_->SetStatus(ServiceWorkerVersion::INSTALLING); | 603 version_->SetStatus(ServiceWorkerVersion::INSTALLING); |
602 version_->RunAfterStartWorker( | 604 version_->RunAfterStartWorker( |
| 605 ServiceWorkerMetrics::EventType::INSTALL, |
603 base::Bind(&self::DispatchInstallEventOnIOThread, this, done, result), | 606 base::Bind(&self::DispatchInstallEventOnIOThread, this, done, result), |
604 CreateReceiver(BrowserThread::UI, done, result)); | 607 CreateReceiver(BrowserThread::UI, done, result)); |
605 } | 608 } |
606 | 609 |
607 void DispatchInstallEventOnIOThread(const base::Closure& done, | 610 void DispatchInstallEventOnIOThread(const base::Closure& done, |
608 ServiceWorkerStatusCode* result) { | 611 ServiceWorkerStatusCode* result) { |
609 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 612 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
610 int request_id = | 613 int request_id = |
611 version_->StartRequest(ServiceWorkerMetrics::EventType::INSTALL, | 614 version_->StartRequest(ServiceWorkerMetrics::EventType::INSTALL, |
612 CreateReceiver(BrowserThread::UI, done, result)); | 615 CreateReceiver(BrowserThread::UI, done, result)); |
(...skipping 11 matching lines...) Expand all Loading... |
624 registration_.get(), version, | 627 registration_.get(), version, |
625 CreateReceiver(BrowserThread::UI, done, result)); | 628 CreateReceiver(BrowserThread::UI, done, result)); |
626 } | 629 } |
627 | 630 |
628 void ActivateOnIOThread(const base::Closure& done, | 631 void ActivateOnIOThread(const base::Closure& done, |
629 ServiceWorkerStatusCode* result) { | 632 ServiceWorkerStatusCode* result) { |
630 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 633 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
631 version_->SetStatus(ServiceWorkerVersion::ACTIVATING); | 634 version_->SetStatus(ServiceWorkerVersion::ACTIVATING); |
632 registration_->SetActiveVersion(version_.get()); | 635 registration_->SetActiveVersion(version_.get()); |
633 version_->RunAfterStartWorker( | 636 version_->RunAfterStartWorker( |
| 637 ServiceWorkerMetrics::EventType::ACTIVATE, |
634 base::Bind(&self::DispatchActivateEventOnIOThread, this, done, result), | 638 base::Bind(&self::DispatchActivateEventOnIOThread, this, done, result), |
635 CreateReceiver(BrowserThread::UI, done, result)); | 639 CreateReceiver(BrowserThread::UI, done, result)); |
636 } | 640 } |
637 | 641 |
638 void DispatchActivateEventOnIOThread(const base::Closure& done, | 642 void DispatchActivateEventOnIOThread(const base::Closure& done, |
639 ServiceWorkerStatusCode* result) { | 643 ServiceWorkerStatusCode* result) { |
640 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 644 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
641 int request_id = | 645 int request_id = |
642 version_->StartRequest(ServiceWorkerMetrics::EventType::INSTALL, | 646 version_->StartRequest(ServiceWorkerMetrics::EventType::INSTALL, |
643 CreateReceiver(BrowserThread::UI, done, result)); | 647 CreateReceiver(BrowserThread::UI, done, result)); |
644 version_->DispatchSimpleEvent<ServiceWorkerHostMsg_ActivateEventFinished>( | 648 version_->DispatchSimpleEvent<ServiceWorkerHostMsg_ActivateEventFinished>( |
645 request_id, ServiceWorkerMsg_ActivateEvent(request_id)); | 649 request_id, ServiceWorkerMsg_ActivateEvent(request_id)); |
646 } | 650 } |
647 | 651 |
648 void FetchOnIOThread(const base::Closure& done, | 652 void FetchOnIOThread(const base::Closure& done, |
649 bool* prepare_result, | 653 bool* prepare_result, |
650 FetchResult* result) { | 654 FetchResult* result) { |
651 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 655 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
652 scoped_ptr<ServiceWorkerFetchRequest> request(new ServiceWorkerFetchRequest( | 656 scoped_ptr<ServiceWorkerFetchRequest> request(new ServiceWorkerFetchRequest( |
653 embedded_test_server()->GetURL("/service_worker/empty.html"), "GET", | 657 embedded_test_server()->GetURL("/service_worker/empty.html"), "GET", |
654 ServiceWorkerHeaderMap(), Referrer(), false)); | 658 ServiceWorkerHeaderMap(), Referrer(), false)); |
655 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); | 659 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); |
656 fetch_dispatcher_.reset(new ServiceWorkerFetchDispatcher( | 660 fetch_dispatcher_.reset(new ServiceWorkerFetchDispatcher( |
657 std::move(request), version_.get(), | 661 std::move(request), version_.get(), RESOURCE_TYPE_MAIN_FRAME, |
658 CreatePrepareReceiver(prepare_result), | 662 CreatePrepareReceiver(prepare_result), |
659 CreateResponseReceiver(done, blob_context_.get(), result))); | 663 CreateResponseReceiver(done, blob_context_.get(), result))); |
660 fetch_dispatcher_->Run(); | 664 fetch_dispatcher_->Run(); |
661 } | 665 } |
662 | 666 |
663 // Contrary to the style guide, the output parameter of this function comes | 667 // Contrary to the style guide, the output parameter of this function comes |
664 // before input parameters so Bind can be used on it to create a FetchCallback | 668 // before input parameters so Bind can be used on it to create a FetchCallback |
665 // to pass to DispatchFetchEvent. | 669 // to pass to DispatchFetchEvent. |
666 void ReceiveFetchResultOnIOThread( | 670 void ReceiveFetchResultOnIOThread( |
667 const base::Closure& quit, | 671 const base::Closure& quit, |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
870 const base::string16 expected = | 874 const base::string16 expected = |
871 base::ASCIIToUTF16("Rejecting oninstall event"); | 875 base::ASCIIToUTF16("Rejecting oninstall event"); |
872 console_listener.WaitForConsoleMessages(1); | 876 console_listener.WaitForConsoleMessages(1); |
873 ASSERT_NE(base::string16::npos, | 877 ASSERT_NE(base::string16::npos, |
874 console_listener.messages()[0].find(expected)); | 878 console_listener.messages()[0].find(expected)); |
875 version_->embedded_worker()->RemoveListener(&console_listener); | 879 version_->embedded_worker()->RemoveListener(&console_listener); |
876 } | 880 } |
877 | 881 |
878 class WaitForLoaded : public EmbeddedWorkerInstance::Listener { | 882 class WaitForLoaded : public EmbeddedWorkerInstance::Listener { |
879 public: | 883 public: |
880 WaitForLoaded(const base::Closure& quit) : quit_(quit) {} | 884 explicit WaitForLoaded(const base::Closure& quit) : quit_(quit) {} |
881 | 885 |
882 void OnThreadStarted() override { | 886 void OnThreadStarted() override { |
883 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, quit_); | 887 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, quit_); |
884 } | 888 } |
885 bool OnMessageReceived(const IPC::Message& message) override { return false; } | 889 bool OnMessageReceived(const IPC::Message& message) override { return false; } |
886 | 890 |
887 private: | 891 private: |
888 base::Closure quit_; | 892 base::Closure quit_; |
889 }; | 893 }; |
890 | 894 |
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1484 ASSERT_EQ(SERVICE_WORKER_OK, status); | 1488 ASSERT_EQ(SERVICE_WORKER_OK, status); |
1485 // Stop the worker. | 1489 // Stop the worker. |
1486 StopWorker(SERVICE_WORKER_OK); | 1490 StopWorker(SERVICE_WORKER_OK); |
1487 // Restart the worker. | 1491 // Restart the worker. |
1488 StartWorker(SERVICE_WORKER_OK); | 1492 StartWorker(SERVICE_WORKER_OK); |
1489 // Stop the worker. | 1493 // Stop the worker. |
1490 StopWorker(SERVICE_WORKER_OK); | 1494 StopWorker(SERVICE_WORKER_OK); |
1491 } | 1495 } |
1492 | 1496 |
1493 } // namespace content | 1497 } // namespace content |
OLD | NEW |