1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "base/command_line.h" 6 #include "chrome/browser/extensions/extension_apitest.h" 7 #include "chrome/browser/extensions/extension_service.h" 8 #include "chrome/browser/extensions/extension_webnavigation_api.h" 9 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/ui/browser.h" 11 #include "chrome/common/chrome_switches.h" 12 #include "chrome/test/ui_test_utils.h" 13 #include "content/browser/tab_contents/tab_contents.h" 14 15 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigation) { 16 CommandLine::ForCurrentProcess()->AppendSwitch( 17 switches::kEnableExperimentalExtensionApis); 18 19 FrameNavigationState::set_allow_extension_scheme(true); 20 21 ASSERT_TRUE(RunExtensionTest("webnavigation/api")) << message_; 22 } 23 24 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationClientRedirect) { 25 CommandLine::ForCurrentProcess()->AppendSwitch( 26 switches::kEnableExperimentalExtensionApis); 27 28 FrameNavigationState::set_allow_extension_scheme(true); 29 30 ASSERT_TRUE(RunExtensionTest("webnavigation/clientRedirect")) << message_; 31 } 32 33 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationForwardBack) { 34 CommandLine::ForCurrentProcess()->AppendSwitch( 35 switches::kEnableExperimentalExtensionApis); 36 37 FrameNavigationState::set_allow_extension_scheme(true); 38 39 ASSERT_TRUE(RunExtensionTest("webnavigation/forwardBack")) << message_; 40 } 41 42 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationIFrame) { 43 CommandLine::ForCurrentProcess()->AppendSwitch( 44 switches::kEnableExperimentalExtensionApis); 45 46 FrameNavigationState::set_allow_extension_scheme(true); 47 48 ASSERT_TRUE(RunExtensionTest("webnavigation/iframe")) << message_; 49 } 50 51 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationOpenTab) { 52 CommandLine::ForCurrentProcess()->AppendSwitch( 53 switches::kEnableExperimentalExtensionApis); 54 55 FrameNavigationState::set_allow_extension_scheme(true); 56 57 ASSERT_TRUE(RunExtensionTest("webnavigation/openTab")) << message_; 58 } 59 60 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationReferenceFragment) { 61 CommandLine::ForCurrentProcess()->AppendSwitch( 62 switches::kEnableExperimentalExtensionApis); 63 64 FrameNavigationState::set_allow_extension_scheme(true); 65 66 ASSERT_TRUE(RunExtensionTest("webnavigation/referenceFragment")) << message_; 67 } 68 69 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationSimpleLoad) { 70 CommandLine::ForCurrentProcess()->AppendSwitch( 71 switches::kEnableExperimentalExtensionApis); 72 73 FrameNavigationState::set_allow_extension_scheme(true); 74 75 ASSERT_TRUE(RunExtensionTest("webnavigation/simpleLoad")) << message_; 76 } 77 78 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationFailures) { 79 CommandLine::ForCurrentProcess()->AppendSwitch( 80 switches::kEnableExperimentalExtensionApis); 81 82 FrameNavigationState::set_allow_extension_scheme(true); 83 84 ASSERT_TRUE(RunExtensionTest("webnavigation/failures")) << message_; 85 } 86 87 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationUserAction) { 88 CommandLine::ForCurrentProcess()->AppendSwitch( 89 switches::kEnableExperimentalExtensionApis); 90 91 FrameNavigationState::set_allow_extension_scheme(true); 92 93 // Wait for the extension to set itself up and return control to us. 94 ASSERT_TRUE(RunExtensionTest("webnavigation/userAction")) << message_; 95 96 ResultCatcher catcher; 97 98 ExtensionService* service = browser()->profile()->GetExtensionService(); 99 const Extension* extension = 100 service->GetExtensionById(last_loaded_extension_id_, false); 101 GURL url = extension->GetResourceURL("a.html"); 102 103 ui_test_utils::NavigateToURL(browser(), url); 104 105 url = extension->GetResourceURL("b.html"); 106 // This corresponds to "Open link in new tab". 107 browser()->GetSelectedTabContents()->OpenURL( 108 url, GURL(), NEW_BACKGROUND_TAB, PageTransition::LINK); 109 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); 110 } 111