OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <set> | 5 #include <set> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "base/task_runner_util.h" | 12 #include "base/task_runner_util.h" |
13 #include "content/browser/background_sync/background_sync_manager.h" | 13 #include "content/browser/background_sync/background_sync_manager.h" |
14 #include "content/browser/background_sync/background_sync_network_observer.h" | 14 #include "content/browser/background_sync/background_sync_network_observer.h" |
15 #include "content/browser/background_sync/background_sync_registration_handle.h" | 15 #include "content/browser/background_sync/background_sync_registration_handle.h" |
16 #include "content/browser/background_sync/background_sync_status.h" | 16 #include "content/browser/background_sync/background_sync_status.h" |
17 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 17 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
18 #include "content/browser/service_worker/service_worker_registration.h" | 18 #include "content/browser/service_worker/service_worker_registration.h" |
19 #include "content/public/browser/background_sync_context.h" | 19 #include "content/public/browser/background_sync_context.h" |
20 #include "content/public/browser/browser_context.h" | 20 #include "content/public/browser/browser_context.h" |
21 #include "content/public/browser/storage_partition.h" | 21 #include "content/public/browser/storage_partition.h" |
22 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
23 #include "content/public/common/content_switches.h" | 23 #include "content/public/common/content_switches.h" |
24 #include "content/public/test/browser_test_utils.h" | 24 #include "content/public/test/browser_test_utils.h" |
25 #include "content/public/test/content_browser_test.h" | 25 #include "content/public/test/content_browser_test.h" |
26 #include "content/public/test/content_browser_test_utils.h" | 26 #include "content/public/test/content_browser_test_utils.h" |
27 #include "content/public/test/test_utils.h" | 27 #include "content/public/test/test_utils.h" |
28 #include "content/shell/browser/shell.h" | 28 #include "content/shell/browser/shell.h" |
29 #include "net/base/network_change_notifier.h" | 29 #include "net/base/network_change_notifier.h" |
| 30 #include "net/test/embedded_test_server/embedded_test_server.h" |
30 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
31 | 32 |
32 using net::NetworkChangeNotifier; | 33 using net::NetworkChangeNotifier; |
33 | 34 |
34 namespace content { | 35 namespace content { |
35 | 36 |
36 namespace { | 37 namespace { |
37 | 38 |
38 const char kDefaultTestURL[] = "files/background_sync/test.html"; | 39 const char kDefaultTestURL[] = "/background_sync/test.html"; |
39 | 40 |
40 const char kSuccessfulOperationPrefix[] = "ok - "; | 41 const char kSuccessfulOperationPrefix[] = "ok - "; |
41 | 42 |
42 std::string BuildScriptString(const std::string& function, | 43 std::string BuildScriptString(const std::string& function, |
43 const std::string& argument) { | 44 const std::string& argument) { |
44 return base::StringPrintf("%s('%s');", function.c_str(), argument.c_str()); | 45 return base::StringPrintf("%s('%s');", function.c_str(), argument.c_str()); |
45 } | 46 } |
46 | 47 |
47 std::string BuildExpectedResult(const std::string& tag, | 48 std::string BuildExpectedResult(const std::string& tag, |
48 const std::string& action) { | 49 const std::string& action) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 } | 117 } |
117 | 118 |
118 void SetUpCommandLine(base::CommandLine* command_line) override { | 119 void SetUpCommandLine(base::CommandLine* command_line) override { |
119 // TODO(jkarlin): Remove this once background sync is no longer | 120 // TODO(jkarlin): Remove this once background sync is no longer |
120 // experimental. | 121 // experimental. |
121 command_line->AppendSwitch( | 122 command_line->AppendSwitch( |
122 switches::kEnableExperimentalWebPlatformFeatures); | 123 switches::kEnableExperimentalWebPlatformFeatures); |
123 } | 124 } |
124 | 125 |
125 void SetUpOnMainThread() override { | 126 void SetUpOnMainThread() override { |
126 https_server_.reset(new net::SpawnedTestServer( | 127 https_server_.reset( |
127 net::SpawnedTestServer::TYPE_HTTPS, | 128 new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS)); |
128 net::BaseTestServer::SSLOptions( | 129 https_server_->ServeFilesFromSourceDirectory("content/test/data"); |
129 net::BaseTestServer::SSLOptions::CERT_OK), | |
130 base::FilePath(FILE_PATH_LITERAL("content/test/data/")))); | |
131 ASSERT_TRUE(https_server_->Start()); | 130 ASSERT_TRUE(https_server_->Start()); |
132 | 131 |
133 SetIncognitoMode(false); | 132 SetIncognitoMode(false); |
134 | 133 |
135 SetOnline(true); | 134 SetOnline(true); |
136 | 135 |
137 ASSERT_TRUE(LoadTestPage(kDefaultTestURL)); | 136 ASSERT_TRUE(LoadTestPage(kDefaultTestURL)); |
138 | 137 |
139 ContentBrowserTest::SetUpOnMainThread(); | 138 ContentBrowserTest::SetUpOnMainThread(); |
140 } | 139 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 bool GetRegistrationsOneShot(const std::vector<std::string>& expected_tags); | 175 bool GetRegistrationsOneShot(const std::vector<std::string>& expected_tags); |
177 bool GetRegistrationsOneShotFromServiceWorker( | 176 bool GetRegistrationsOneShotFromServiceWorker( |
178 const std::vector<std::string>& expected_tags); | 177 const std::vector<std::string>& expected_tags); |
179 bool CompleteDelayedOneShot(); | 178 bool CompleteDelayedOneShot(); |
180 bool RejectDelayedOneShot(); | 179 bool RejectDelayedOneShot(); |
181 bool NotifyWhenFinishedOneShot(const std::string& tag); | 180 bool NotifyWhenFinishedOneShot(const std::string& tag); |
182 bool NotifyWhenFinishedImmediateOneShot(const std::string& expected_msg); | 181 bool NotifyWhenFinishedImmediateOneShot(const std::string& expected_msg); |
183 bool StoreRegistrationOneShot(const std::string& tag); | 182 bool StoreRegistrationOneShot(const std::string& tag); |
184 | 183 |
185 private: | 184 private: |
186 scoped_ptr<net::SpawnedTestServer> https_server_; | 185 scoped_ptr<net::EmbeddedTestServer> https_server_; |
187 Shell* shell_ = nullptr; | 186 Shell* shell_ = nullptr; |
188 | 187 |
189 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncBrowserTest); | 188 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncBrowserTest); |
190 }; | 189 }; |
191 | 190 |
192 void BackgroundSyncBrowserTest::SetOnline(bool online) { | 191 void BackgroundSyncBrowserTest::SetOnline(bool online) { |
193 ASSERT_TRUE(shell_); | 192 ASSERT_TRUE(shell_); |
194 BrowserThread::PostTask( | 193 BrowserThread::PostTask( |
195 BrowserThread::IO, FROM_HERE, | 194 BrowserThread::IO, FROM_HERE, |
196 base::Bind(&BackgroundSyncBrowserTest::SetOnlineOnIOThread, | 195 base::Bind(&BackgroundSyncBrowserTest::SetOnlineOnIOThread, |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 EXPECT_TRUE(RegisterOneShot("delay")); | 631 EXPECT_TRUE(RegisterOneShot("delay")); |
633 EXPECT_FALSE(OneShotPending("delay")); | 632 EXPECT_FALSE(OneShotPending("delay")); |
634 EXPECT_TRUE(StoreRegistrationOneShot("delay")); | 633 EXPECT_TRUE(StoreRegistrationOneShot("delay")); |
635 | 634 |
636 EXPECT_TRUE(RejectDelayedOneShot()); | 635 EXPECT_TRUE(RejectDelayedOneShot()); |
637 EXPECT_TRUE(PopConsole("ok - delay rejected")); | 636 EXPECT_TRUE(PopConsole("ok - delay rejected")); |
638 EXPECT_TRUE(NotifyWhenFinishedImmediateOneShot("ok - delay result: false")); | 637 EXPECT_TRUE(NotifyWhenFinishedImmediateOneShot("ok - delay result: false")); |
639 } | 638 } |
640 | 639 |
641 } // namespace content | 640 } // namespace content |
OLD | NEW |