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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/logging.h" | 6 #include "base/logging.h" |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 #include "chrome/browser/extensions/extension_apitest.h" | 8 #include "chrome/browser/extensions/extension_apitest.h" |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 11 #include "chrome/common/chrome_switches.h" |
| 12 #include "chrome/test/base/test_switches.h" |
11 #include "chrome/test/base/ui_test_utils.h" | 13 #include "chrome/test/base/ui_test_utils.h" |
| 14 #include "content/public/browser/navigation_handle.h" |
12 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 16 #include "content/public/browser/web_contents_observer.h" |
13 #include "content/public/test/browser_test_utils.h" | 17 #include "content/public/test/browser_test_utils.h" |
14 #include "extensions/common/switches.h" | 18 #include "extensions/common/switches.h" |
15 #include "net/dns/mock_host_resolver.h" | 19 #include "net/dns/mock_host_resolver.h" |
16 #include "net/test/embedded_test_server/embedded_test_server.h" | 20 #include "net/test/embedded_test_server/embedded_test_server.h" |
17 #include "url/gurl.h" | 21 #include "url/gurl.h" |
18 | 22 |
19 class ExtensionResourceRequestPolicyTest : public ExtensionApiTest { | 23 class ExtensionResourceRequestPolicyTest : public ExtensionApiTest { |
20 protected: | 24 protected: |
21 void SetUpCommandLine(base::CommandLine* command_line) override { | 25 void SetUpCommandLine(base::CommandLine* command_line) override { |
22 ExtensionApiTest::SetUpCommandLine(command_line); | 26 ExtensionApiTest::SetUpCommandLine(command_line); |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 | 316 |
313 #if defined(OS_MACOSX) | 317 #if defined(OS_MACOSX) |
314 #define MAYBE_ExtensionAccessibleResources DISABLED_ExtensionAccessibleResources | 318 #define MAYBE_ExtensionAccessibleResources DISABLED_ExtensionAccessibleResources |
315 #else | 319 #else |
316 #define MAYBE_ExtensionAccessibleResources ExtensionAccessibleResources | 320 #define MAYBE_ExtensionAccessibleResources ExtensionAccessibleResources |
317 #endif | 321 #endif |
318 IN_PROC_BROWSER_TEST_F(ExtensionResourceRequestPolicyTest, | 322 IN_PROC_BROWSER_TEST_F(ExtensionResourceRequestPolicyTest, |
319 MAYBE_ExtensionAccessibleResources) { | 323 MAYBE_ExtensionAccessibleResources) { |
320 ASSERT_TRUE(RunExtensionSubtest("accessible_cer", "main.html")) << message_; | 324 ASSERT_TRUE(RunExtensionSubtest("accessible_cer", "main.html")) << message_; |
321 } | 325 } |
| 326 |
| 327 class NavigationErrorObserver : public content::WebContentsObserver { |
| 328 public: |
| 329 NavigationErrorObserver(content::WebContents* web_contents, const GURL& url) |
| 330 : content::WebContentsObserver(web_contents), |
| 331 url_(url), |
| 332 saw_navigation_(false) {} |
| 333 |
| 334 void DidFinishNavigation(content::NavigationHandle* handle) override { |
| 335 if (handle->GetURL() != url_) |
| 336 return; |
| 337 EXPECT_TRUE(handle->IsErrorPage()); |
| 338 saw_navigation_ = true; |
| 339 if (run_loop_.running()) |
| 340 run_loop_.Quit(); |
| 341 } |
| 342 |
| 343 void Wait() { |
| 344 if (!saw_navigation_) |
| 345 run_loop_.Run(); |
| 346 } |
| 347 |
| 348 private: |
| 349 // The url we want to see a navigation for. |
| 350 GURL url_; |
| 351 |
| 352 // Have we seen the navigation for |url_| yet? |
| 353 bool saw_navigation_; |
| 354 |
| 355 base::RunLoop run_loop_; |
| 356 |
| 357 DISALLOW_COPY_AND_ASSIGN(NavigationErrorObserver); |
| 358 }; |
| 359 |
| 360 IN_PROC_BROWSER_TEST_F(ExtensionResourceRequestPolicyTest, |
| 361 IframeNavigateToInaccessible) { |
| 362 ASSERT_TRUE(embedded_test_server()->Start()); |
| 363 ASSERT_TRUE(LoadExtension( |
| 364 test_data_dir_.AppendASCII("extension_resource_request_policy") |
| 365 .AppendASCII("some_accessible"))); |
| 366 |
| 367 GURL iframe_navigate_url(embedded_test_server()->GetURL( |
| 368 "/extensions/api_test/extension_resource_request_policy/" |
| 369 "iframe_navigate.html")); |
| 370 |
| 371 ui_test_utils::NavigateToURL(browser(), iframe_navigate_url); |
| 372 |
| 373 content::WebContents* web_contents = |
| 374 browser()->tab_strip_model()->GetActiveWebContents(); |
| 375 |
| 376 GURL private_page( |
| 377 "chrome-extension://kegmjfcnjamahdnldjmlpachmpielcdk/private.html"); |
| 378 NavigationErrorObserver observer(web_contents, private_page); |
| 379 ASSERT_TRUE(content::ExecuteScript(web_contents, "navigateFrameNow()")); |
| 380 observer.Wait(); |
| 381 } |
OLD | NEW |