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
3 // found in the LICENSE file.
4
5 #include "build/build_config.h"
6 #include "chrome/browser/extensions/extension_apitest.h"
7 #include "chrome/browser/extensions/extension_service.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/tabs/tab_strip_model.h"
11 #include "chrome/test/base/ui_test_utils.h"
12 #include "content/public/browser/web_contents.h"
13 #include "content/public/test/browser_test.h"
14 #include "content/public/test/browser_test_utils.h"
15 #include "extensions/common/switches.h"
16 #include "net/dns/mock_host_resolver.h"
17 #include "url/gurl.h"
18
19 using ExtensionIconSourceTest = extensions::ExtensionApiTest;
20
IN_PROC_BROWSER_TEST_F(ExtensionIconSourceTest,IconsLoaded)21 IN_PROC_BROWSER_TEST_F(ExtensionIconSourceTest, IconsLoaded) {
22 base::FilePath basedir = test_data_dir_.AppendASCII("icons");
23 ASSERT_TRUE(LoadExtension(basedir.AppendASCII("extension_with_permission")));
24 ASSERT_TRUE(LoadExtension(basedir.AppendASCII("extension_no_permission")));
25 std::string result;
26
27 // Test that the icons are loaded and that the chrome://extension-icon
28 // parameters work correctly.
29 ui_test_utils::NavigateToURL(
30 browser(),
31 GURL("chrome-extension://gbmgkahjioeacddebbnengilkgbkhodg/index.html"));
32 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
33 browser()->tab_strip_model()->GetActiveWebContents(),
34 "window.domAutomationController.send(document.title)",
35 &result));
36 EXPECT_EQ(result, "Loaded");
37
38 // Verify that the an extension can't load chrome://extension-icon icons
39 // without the management permission.
40 ui_test_utils::NavigateToURL(
41 browser(),
42 GURL("chrome-extension://apocjbpjpkghdepdngjlknfpmabcmlao/index.html"));
43 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
44 browser()->tab_strip_model()->GetActiveWebContents(),
45 "window.domAutomationController.send(document.title)",
46 &result));
47 EXPECT_EQ(result, "Not Loaded");
48 }
49
IN_PROC_BROWSER_TEST_F(ExtensionIconSourceTest,InvalidURL)50 IN_PROC_BROWSER_TEST_F(ExtensionIconSourceTest, InvalidURL) {
51 std::string result;
52
53 // Test that navigation to an invalid url works.
54 ui_test_utils::NavigateToURL(
55 browser(),
56 GURL("chrome://extension-icon/invalid"));
57
58 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
59 browser()->tab_strip_model()->GetActiveWebContents(),
60 "window.domAutomationController.send(document.title)",
61 &result));
62 EXPECT_EQ(result, "invalid (96\xC3\x97""96)");
63 }
64
IN_PROC_BROWSER_TEST_F(ExtensionIconSourceTest,IconsLoadedIncognito)65 IN_PROC_BROWSER_TEST_F(ExtensionIconSourceTest, IconsLoadedIncognito) {
66 base::FilePath basedir = test_data_dir_.AppendASCII("icons");
67 ASSERT_TRUE(LoadExtensionIncognito(
68 basedir.AppendASCII("extension_with_permission")));
69 ASSERT_TRUE(LoadExtensionIncognito(
70 basedir.AppendASCII("extension_no_permission")));
71 std::string result;
72
73 // Test that the icons are loaded and that the chrome://extension-icon
74 // parameters work correctly.
75 Browser* otr_browser = OpenURLOffTheRecord(
76 browser()->profile(),
77 GURL("chrome-extension://gbmgkahjioeacddebbnengilkgbkhodg/index.html"));
78 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
79 otr_browser->tab_strip_model()->GetActiveWebContents(),
80 "window.domAutomationController.send(document.title)",
81 &result));
82 EXPECT_EQ(result, "Loaded");
83
84 // Verify that the an extension can't load chrome://extension-icon icons
85 // without the management permission.
86 OpenURLOffTheRecord(
87 browser()->profile(),
88 GURL("chrome-extension://apocjbpjpkghdepdngjlknfpmabcmlao/index.html"));
89 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
90 otr_browser->tab_strip_model()->GetActiveWebContents(),
91 "window.domAutomationController.send(document.title)",
92 &result));
93 EXPECT_EQ(result, "Not Loaded");
94 }
95