OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <algorithm> | 5 #include <algorithm> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 #include "content/public/common/process_type.h" | 116 #include "content/public/common/process_type.h" |
117 #include "content/public/common/result_codes.h" | 117 #include "content/public/common/result_codes.h" |
118 #include "content/public/common/url_constants.h" | 118 #include "content/public/common/url_constants.h" |
119 #include "content/public/common/webplugininfo.h" | 119 #include "content/public/common/webplugininfo.h" |
120 #include "content/public/test/browser_test_utils.h" | 120 #include "content/public/test/browser_test_utils.h" |
121 #include "content/public/test/download_test_observer.h" | 121 #include "content/public/test/download_test_observer.h" |
122 #include "content/public/test/mock_notification_observer.h" | 122 #include "content/public/test/mock_notification_observer.h" |
123 #include "content/public/test/test_navigation_observer.h" | 123 #include "content/public/test/test_navigation_observer.h" |
124 #include "content/public/test/test_utils.h" | 124 #include "content/public/test/test_utils.h" |
125 #include "content/test/net/url_request_failed_job.h" | 125 #include "content/test/net/url_request_failed_job.h" |
126 #include "content/test/net/url_request_mock_http_job.h" | |
127 #include "extensions/browser/extension_host.h" | 126 #include "extensions/browser/extension_host.h" |
128 #include "extensions/browser/extension_system.h" | 127 #include "extensions/browser/extension_system.h" |
129 #include "extensions/browser/process_manager.h" | 128 #include "extensions/browser/process_manager.h" |
130 #include "extensions/browser/uninstall_reason.h" | 129 #include "extensions/browser/uninstall_reason.h" |
131 #include "extensions/common/constants.h" | 130 #include "extensions/common/constants.h" |
132 #include "extensions/common/extension.h" | 131 #include "extensions/common/extension.h" |
133 #include "extensions/common/extension_set.h" | 132 #include "extensions/common/extension_set.h" |
134 #include "net/base/net_errors.h" | 133 #include "net/base/net_errors.h" |
135 #include "net/base/net_util.h" | 134 #include "net/base/net_util.h" |
136 #include "net/base/url_util.h" | 135 #include "net/base/url_util.h" |
137 #include "net/http/http_stream_factory.h" | 136 #include "net/http/http_stream_factory.h" |
| 137 #include "net/test/url_request/url_request_mock_http_job.h" |
138 #include "net/url_request/url_request.h" | 138 #include "net/url_request/url_request.h" |
139 #include "net/url_request/url_request_filter.h" | 139 #include "net/url_request/url_request_filter.h" |
140 #include "policy/policy_constants.h" | 140 #include "policy/policy_constants.h" |
141 #include "testing/gmock/include/gmock/gmock.h" | 141 #include "testing/gmock/include/gmock/gmock.h" |
142 #include "testing/gtest/include/gtest/gtest.h" | 142 #include "testing/gtest/include/gtest/gtest.h" |
143 #include "third_party/WebKit/public/web/WebInputEvent.h" | 143 #include "third_party/WebKit/public/web/WebInputEvent.h" |
144 #include "ui/base/l10n/l10n_util.h" | 144 #include "ui/base/l10n/l10n_util.h" |
145 #include "ui/base/resource/resource_bundle.h" | 145 #include "ui/base/resource/resource_bundle.h" |
146 #include "url/gurl.h" | 146 #include "url/gurl.h" |
147 | 147 |
(...skipping 14 matching lines...) Expand all Loading... |
162 #include "base/basictypes.h" | 162 #include "base/basictypes.h" |
163 #include "base/compiler_specific.h" | 163 #include "base/compiler_specific.h" |
164 #include "chrome/browser/ui/extensions/application_launch.h" | 164 #include "chrome/browser/ui/extensions/application_launch.h" |
165 #include "extensions/browser/app_window/app_window.h" | 165 #include "extensions/browser/app_window/app_window.h" |
166 #include "extensions/browser/app_window/app_window_registry.h" | 166 #include "extensions/browser/app_window/app_window_registry.h" |
167 #include "extensions/browser/app_window/native_app_window.h" | 167 #include "extensions/browser/app_window/native_app_window.h" |
168 #include "ui/base/window_open_disposition.h" | 168 #include "ui/base/window_open_disposition.h" |
169 #endif | 169 #endif |
170 | 170 |
171 using content::BrowserThread; | 171 using content::BrowserThread; |
172 using content::URLRequestMockHTTPJob; | 172 using net::URLRequestMockHTTPJob; |
173 using testing::Mock; | 173 using testing::Mock; |
174 using testing::Return; | 174 using testing::Return; |
175 using testing::_; | 175 using testing::_; |
176 | 176 |
177 namespace policy { | 177 namespace policy { |
178 | 178 |
179 namespace { | 179 namespace { |
180 | 180 |
181 #if defined(OS_CHROMEOS) | 181 #if defined(OS_CHROMEOS) |
182 const int kOneHourInMs = 60 * 60 * 1000; | 182 const int kOneHourInMs = 60 * 60 * 1000; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 // dir through URLRequestMockHTTPJobs. | 218 // dir through URLRequestMockHTTPJobs. |
219 void RedirectHostsToTestData(const char* const urls[], size_t size) { | 219 void RedirectHostsToTestData(const char* const urls[], size_t size) { |
220 // Map the given hosts to the test data dir. | 220 // Map the given hosts to the test data dir. |
221 net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance(); | 221 net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance(); |
222 base::FilePath base_path; | 222 base::FilePath base_path; |
223 PathService::Get(chrome::DIR_TEST_DATA, &base_path); | 223 PathService::Get(chrome::DIR_TEST_DATA, &base_path); |
224 for (size_t i = 0; i < size; ++i) { | 224 for (size_t i = 0; i < size; ++i) { |
225 const GURL url(urls[i]); | 225 const GURL url(urls[i]); |
226 EXPECT_TRUE(url.is_valid()); | 226 EXPECT_TRUE(url.is_valid()); |
227 filter->AddUrlInterceptor( | 227 filter->AddUrlInterceptor( |
228 url, URLRequestMockHTTPJob::CreateInterceptor(base_path)); | 228 url, |
| 229 URLRequestMockHTTPJob::CreateInterceptor( |
| 230 base_path, content::BrowserThread::GetBlockingPool())); |
229 } | 231 } |
230 } | 232 } |
231 | 233 |
232 // Remove filters for requests to the hosts in |urls|. | 234 // Remove filters for requests to the hosts in |urls|. |
233 void UndoRedirectHostsToTestData(const char* const urls[], size_t size) { | 235 void UndoRedirectHostsToTestData(const char* const urls[], size_t size) { |
234 // Map the given hosts to the test data dir. | 236 // Map the given hosts to the test data dir. |
235 net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance(); | 237 net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance(); |
236 for (size_t i = 0; i < size; ++i) { | 238 for (size_t i = 0; i < size; ++i) { |
237 const GURL url(urls[i]); | 239 const GURL url(urls[i]); |
238 EXPECT_TRUE(url.is_valid()); | 240 EXPECT_TRUE(url.is_valid()); |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 BrowserThread::IO, FROM_HERE, | 613 BrowserThread::IO, FROM_HERE, |
612 base::Bind(chrome_browser_net::SetUrlRequestMocksEnabled, true)); | 614 base::Bind(chrome_browser_net::SetUrlRequestMocksEnabled, true)); |
613 } | 615 } |
614 | 616 |
615 // Makes URLRequestMockHTTPJobs serve data from content::DIR_TEST_DATA | 617 // Makes URLRequestMockHTTPJobs serve data from content::DIR_TEST_DATA |
616 // instead of chrome::DIR_TEST_DATA. | 618 // instead of chrome::DIR_TEST_DATA. |
617 void ServeContentTestData() { | 619 void ServeContentTestData() { |
618 base::FilePath root_http; | 620 base::FilePath root_http; |
619 PathService::Get(content::DIR_TEST_DATA, &root_http); | 621 PathService::Get(content::DIR_TEST_DATA, &root_http); |
620 BrowserThread::PostTaskAndReply( | 622 BrowserThread::PostTaskAndReply( |
621 BrowserThread::IO, FROM_HERE, | 623 BrowserThread::IO, |
622 base::Bind(URLRequestMockHTTPJob::AddUrlHandler, root_http), | 624 FROM_HERE, |
| 625 base::Bind(URLRequestMockHTTPJob::AddUrlHandler, |
| 626 root_http, |
| 627 make_scoped_refptr(BrowserThread::GetBlockingPool())), |
623 base::MessageLoop::current()->QuitWhenIdleClosure()); | 628 base::MessageLoop::current()->QuitWhenIdleClosure()); |
624 content::RunMessageLoop(); | 629 content::RunMessageLoop(); |
625 } | 630 } |
626 | 631 |
627 void SetScreenshotPolicy(bool enabled) { | 632 void SetScreenshotPolicy(bool enabled) { |
628 PolicyMap policies; | 633 PolicyMap policies; |
629 policies.Set(key::kDisableScreenshots, | 634 policies.Set(key::kDisableScreenshots, |
630 POLICY_LEVEL_MANDATORY, | 635 POLICY_LEVEL_MANDATORY, |
631 POLICY_SCOPE_USER, | 636 POLICY_SCOPE_USER, |
632 new base::FundamentalValue(!enabled), | 637 new base::FundamentalValue(!enabled), |
(...skipping 2046 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2679 | 2684 |
2680 // Remove the non-switch arguments, so that session restore kicks in for | 2685 // Remove the non-switch arguments, so that session restore kicks in for |
2681 // these tests. | 2686 // these tests. |
2682 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 2687 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
2683 CommandLine::StringVector argv = command_line->argv(); | 2688 CommandLine::StringVector argv = command_line->argv(); |
2684 argv.erase(std::remove_if(++argv.begin(), argv.end(), IsNonSwitchArgument), | 2689 argv.erase(std::remove_if(++argv.begin(), argv.end(), IsNonSwitchArgument), |
2685 argv.end()); | 2690 argv.end()); |
2686 command_line->InitFromArgv(argv); | 2691 command_line->InitFromArgv(argv); |
2687 ASSERT_TRUE(std::equal(argv.begin(), argv.end(), | 2692 ASSERT_TRUE(std::equal(argv.begin(), argv.end(), |
2688 command_line->argv().begin())); | 2693 command_line->argv().begin())); |
| 2694 } |
2689 | 2695 |
2690 // Redirect the test URLs to the test data directory. | 2696 virtual void SetUpOnMainThread() OVERRIDE { |
2691 RedirectHostsToTestData(kRestoredURLs, arraysize(kRestoredURLs)); | 2697 BrowserThread::PostTask( |
| 2698 BrowserThread::IO, |
| 2699 FROM_HERE, |
| 2700 base::Bind( |
| 2701 RedirectHostsToTestData, kRestoredURLs, arraysize(kRestoredURLs))); |
2692 } | 2702 } |
2693 | 2703 |
2694 void HomepageIsNotNTP() { | 2704 void HomepageIsNotNTP() { |
2695 // Verifies that policy can set the startup pages to the homepage, when | 2705 // Verifies that policy can set the startup pages to the homepage, when |
2696 // the homepage is not the NTP. | 2706 // the homepage is not the NTP. |
2697 PolicyMap policies; | 2707 PolicyMap policies; |
2698 policies.Set( | 2708 policies.Set( |
2699 key::kRestoreOnStartup, | 2709 key::kRestoreOnStartup, |
2700 POLICY_LEVEL_MANDATORY, | 2710 POLICY_LEVEL_MANDATORY, |
2701 POLICY_SCOPE_USER, | 2711 POLICY_SCOPE_USER, |
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3217 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | 3227 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
3218 browser2->tab_strip_model()->GetActiveWebContents(), | 3228 browser2->tab_strip_model()->GetActiveWebContents(), |
3219 "domAutomationController.send(window.showModalDialog !== undefined);", | 3229 "domAutomationController.send(window.showModalDialog !== undefined);", |
3220 &result)); | 3230 &result)); |
3221 EXPECT_TRUE(result); | 3231 EXPECT_TRUE(result); |
3222 } | 3232 } |
3223 | 3233 |
3224 #endif // !defined(CHROME_OS) | 3234 #endif // !defined(CHROME_OS) |
3225 | 3235 |
3226 } // namespace policy | 3236 } // namespace policy |
OLD | NEW |