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/logging.h" | 5 #include "base/logging.h" |
6 #include "chrome/browser/extensions/extension_apitest.h" | 6 #include "chrome/browser/extensions/extension_apitest.h" |
7 #include "chrome/browser/extensions/extension_service.h" | 7 #include "chrome/browser/extensions/extension_service.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/browser_tabstrip.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
11 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
12 #include "chrome/test/base/ui_test_utils.h" | 12 #include "chrome/test/base/ui_test_utils.h" |
13 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
14 #include "content/public/test/browser_test_utils.h" | 14 #include "content/public/test/browser_test_utils.h" |
15 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
16 #include "net/base/mock_host_resolver.h" | 16 #include "net/base/mock_host_resolver.h" |
17 | 17 |
18 class ExtensionIconSourceTest : public ExtensionApiTest { | 18 class ExtensionIconSourceTest : public ExtensionApiTest { |
19 protected: | 19 protected: |
20 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 20 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
21 ExtensionApiTest::SetUpCommandLine(command_line); | 21 ExtensionApiTest::SetUpCommandLine(command_line); |
22 command_line->AppendSwitch(switches::kAllowLegacyExtensionManifests); | 22 command_line->AppendSwitch(switches::kAllowLegacyExtensionManifests); |
23 } | 23 } |
24 }; | 24 }; |
25 | 25 |
26 IN_PROC_BROWSER_TEST_F(ExtensionIconSourceTest, IconsLoaded) { | 26 IN_PROC_BROWSER_TEST_F(ExtensionIconSourceTest, IconsLoaded) { |
27 FilePath basedir = test_data_dir_.AppendASCII("icons"); | 27 FilePath basedir = test_data_dir_.AppendASCII("icons"); |
28 ASSERT_TRUE(LoadExtension(basedir.AppendASCII("extension_with_permission"))); | 28 ASSERT_TRUE(LoadExtension(basedir.AppendASCII("extension_with_permission"))); |
29 ASSERT_TRUE(LoadExtension(basedir.AppendASCII("extension_no_permission"))); | 29 ASSERT_TRUE(LoadExtension(basedir.AppendASCII("extension_no_permission"))); |
30 std::string result; | 30 std::string result; |
31 | 31 |
32 // Test that the icons are loaded and that the chrome://extension-icon | 32 // Test that the icons are loaded and that the chrome://extension-icon |
33 // parameters work correctly. | 33 // parameters work correctly. |
34 ui_test_utils::NavigateToURL( | 34 ui_test_utils::NavigateToURL( |
35 browser(), | 35 browser(), |
36 GURL("chrome-extension://gbmgkahjioeacddebbnengilkgbkhodg/index.html")); | 36 GURL("chrome-extension://gbmgkahjioeacddebbnengilkgbkhodg/index.html")); |
37 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | 37 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
38 chrome::GetActiveWebContents(browser()), | 38 browser()->tab_strip_model()->GetActiveWebContents(), |
39 "window.domAutomationController.send(document.title)", | 39 "window.domAutomationController.send(document.title)", |
40 &result)); | 40 &result)); |
41 EXPECT_EQ(result, "Loaded"); | 41 EXPECT_EQ(result, "Loaded"); |
42 | 42 |
43 // Verify that the an extension can't load chrome://extension-icon icons | 43 // Verify that the an extension can't load chrome://extension-icon icons |
44 // without the management permission. | 44 // without the management permission. |
45 ui_test_utils::NavigateToURL( | 45 ui_test_utils::NavigateToURL( |
46 browser(), | 46 browser(), |
47 GURL("chrome-extension://apocjbpjpkghdepdngjlknfpmabcmlao/index.html")); | 47 GURL("chrome-extension://apocjbpjpkghdepdngjlknfpmabcmlao/index.html")); |
48 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | 48 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
49 chrome::GetActiveWebContents(browser()), | 49 browser()->tab_strip_model()->GetActiveWebContents(), |
50 "window.domAutomationController.send(document.title)", | 50 "window.domAutomationController.send(document.title)", |
51 &result)); | 51 &result)); |
52 EXPECT_EQ(result, "Not Loaded"); | 52 EXPECT_EQ(result, "Not Loaded"); |
53 } | 53 } |
54 | 54 |
55 IN_PROC_BROWSER_TEST_F(ExtensionIconSourceTest, IconsLoadedIncognito) { | 55 IN_PROC_BROWSER_TEST_F(ExtensionIconSourceTest, IconsLoadedIncognito) { |
56 FilePath basedir = test_data_dir_.AppendASCII("icons"); | 56 FilePath basedir = test_data_dir_.AppendASCII("icons"); |
57 ASSERT_TRUE(LoadExtensionIncognito( | 57 ASSERT_TRUE(LoadExtensionIncognito( |
58 basedir.AppendASCII("extension_with_permission"))); | 58 basedir.AppendASCII("extension_with_permission"))); |
59 ASSERT_TRUE(LoadExtensionIncognito( | 59 ASSERT_TRUE(LoadExtensionIncognito( |
60 basedir.AppendASCII("extension_no_permission"))); | 60 basedir.AppendASCII("extension_no_permission"))); |
61 std::string result; | 61 std::string result; |
62 | 62 |
63 // Test that the icons are loaded and that the chrome://extension-icon | 63 // Test that the icons are loaded and that the chrome://extension-icon |
64 // parameters work correctly. | 64 // parameters work correctly. |
65 Browser* otr_browser = ui_test_utils::OpenURLOffTheRecord( | 65 Browser* otr_browser = ui_test_utils::OpenURLOffTheRecord( |
66 browser()->profile(), | 66 browser()->profile(), |
67 GURL("chrome-extension://gbmgkahjioeacddebbnengilkgbkhodg/index.html")); | 67 GURL("chrome-extension://gbmgkahjioeacddebbnengilkgbkhodg/index.html")); |
68 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | 68 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
69 chrome::GetActiveWebContents(otr_browser), | 69 otr_browser->tab_strip_model()->GetActiveWebContents(), |
70 "window.domAutomationController.send(document.title)", | 70 "window.domAutomationController.send(document.title)", |
71 &result)); | 71 &result)); |
72 EXPECT_EQ(result, "Loaded"); | 72 EXPECT_EQ(result, "Loaded"); |
73 | 73 |
74 // Verify that the an extension can't load chrome://extension-icon icons | 74 // Verify that the an extension can't load chrome://extension-icon icons |
75 // without the management permission. | 75 // without the management permission. |
76 ui_test_utils::OpenURLOffTheRecord( | 76 ui_test_utils::OpenURLOffTheRecord( |
77 browser()->profile(), | 77 browser()->profile(), |
78 GURL("chrome-extension://apocjbpjpkghdepdngjlknfpmabcmlao/index.html")); | 78 GURL("chrome-extension://apocjbpjpkghdepdngjlknfpmabcmlao/index.html")); |
79 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | 79 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
80 chrome::GetActiveWebContents(otr_browser), | 80 otr_browser->tab_strip_model()->GetActiveWebContents(), |
81 "window.domAutomationController.send(document.title)", | 81 "window.domAutomationController.send(document.title)", |
82 &result)); | 82 &result)); |
83 EXPECT_EQ(result, "Not Loaded"); | 83 EXPECT_EQ(result, "Not Loaded"); |
84 } | 84 } |
OLD | NEW |