blob: 8406ed7c91d6237c4d6327f2564d8ede46b96b05 [file] [log] [blame]
[email protected]d8748142012-05-16 21:13:431// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]f83773f2011-03-02 19:15:212// 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/logging.h"
6#include "chrome/browser/extensions/extension_apitest.h"
[email protected]ff8efd312011-03-21 17:33:597#include "chrome/browser/extensions/extension_service.h"
8#include "chrome/browser/profiles/profile.h"
[email protected]f83773f2011-03-02 19:15:219#include "chrome/browser/ui/browser.h"
[email protected]47ae23372013-01-29 01:50:4810#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]39daa022011-12-07 21:16:2211#include "chrome/common/chrome_switches.h"
[email protected]af44e7fb2011-07-29 18:32:3212#include "chrome/test/base/ui_test_utils.h"
[email protected]4ca15302012-01-03 05:53:2013#include "content/public/browser/web_contents.h"
[email protected]7d478cb2012-07-24 17:19:4214#include "content/public/test/browser_test_utils.h"
[email protected]f2cb3cf2013-03-21 01:40:5315#include "net/dns/mock_host_resolver.h"
[email protected]a6483d22013-07-03 22:11:0016#include "url/gurl.h"
[email protected]f83773f2011-03-02 19:15:2117
18class ExtensionIconSourceTest : public ExtensionApiTest {
[email protected]39daa022011-12-07 21:16:2219 protected:
20 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
21 ExtensionApiTest::SetUpCommandLine(command_line);
22 command_line->AppendSwitch(switches::kAllowLegacyExtensionManifests);
23 }
[email protected]f83773f2011-03-02 19:15:2124};
25
[email protected]04e51aa2013-05-07 17:46:3726// Times out on Mac and Win. http://crbug.com/238705
27#if defined(OS_WIN) || defined(OS_MACOSX)
28#define MAYBE_IconsLoaded DISABLED_IconsLoaded
29#else
30#define MAYBE_IconsLoaded IconsLoaded
31#endif
32
33IN_PROC_BROWSER_TEST_F(ExtensionIconSourceTest, MAYBE_IconsLoaded) {
[email protected]650b2d52013-02-10 03:41:4534 base::FilePath basedir = test_data_dir_.AppendASCII("icons");
[email protected]f83773f2011-03-02 19:15:2135 ASSERT_TRUE(LoadExtension(basedir.AppendASCII("extension_with_permission")));
36 ASSERT_TRUE(LoadExtension(basedir.AppendASCII("extension_no_permission")));
37 std::string result;
38
39 // Test that the icons are loaded and that the chrome://extension-icon
40 // parameters work correctly.
41 ui_test_utils::NavigateToURL(
42 browser(),
43 GURL("chrome-extension://gbmgkahjioeacddebbnengilkgbkhodg/index.html"));
[email protected]b6987e02013-01-04 18:30:4344 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
[email protected]47ae23372013-01-29 01:50:4845 browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]06bc5d92013-01-02 22:44:1346 "window.domAutomationController.send(document.title)",
[email protected]f83773f2011-03-02 19:15:2147 &result));
48 EXPECT_EQ(result, "Loaded");
49
50 // Verify that the an extension can't load chrome://extension-icon icons
51 // without the management permission.
52 ui_test_utils::NavigateToURL(
53 browser(),
54 GURL("chrome-extension://apocjbpjpkghdepdngjlknfpmabcmlao/index.html"));
[email protected]b6987e02013-01-04 18:30:4355 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
[email protected]47ae23372013-01-29 01:50:4856 browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]06bc5d92013-01-02 22:44:1357 "window.domAutomationController.send(document.title)",
[email protected]f83773f2011-03-02 19:15:2158 &result));
59 EXPECT_EQ(result, "Not Loaded");
60}
[email protected]ff8efd312011-03-21 17:33:5961
[email protected]7029cb742013-01-30 02:06:5562IN_PROC_BROWSER_TEST_F(ExtensionIconSourceTest, InvalidURL) {
63 std::string result;
64
65 // Test that navigation to an invalid url works.
66 ui_test_utils::NavigateToURL(
67 browser(),
68 GURL("chrome://extension-icon/invalid"));
69
70 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
71 browser()->tab_strip_model()->GetActiveWebContents(),
72 "window.domAutomationController.send(document.title)",
73 &result));
74 EXPECT_EQ(result, "invalid (96\xC3\x97""96)");
75}
76
[email protected]04e51aa2013-05-07 17:46:3777// Times out on Mac and Win. http://crbug.com/238705
78#if defined(OS_WIN) || defined(OS_MACOSX)
79#define MAYBE_IconsLoadedIncognito DISABLED_IconsLoadedIncognito
80#else
81#define MAYBE_IconsLoadedIncognito IconsLoadedIncognito
82#endif
83
84IN_PROC_BROWSER_TEST_F(ExtensionIconSourceTest, MAYBE_IconsLoadedIncognito) {
[email protected]650b2d52013-02-10 03:41:4585 base::FilePath basedir = test_data_dir_.AppendASCII("icons");
[email protected]ff8efd312011-03-21 17:33:5986 ASSERT_TRUE(LoadExtensionIncognito(
87 basedir.AppendASCII("extension_with_permission")));
88 ASSERT_TRUE(LoadExtensionIncognito(
89 basedir.AppendASCII("extension_no_permission")));
90 std::string result;
91
92 // Test that the icons are loaded and that the chrome://extension-icon
93 // parameters work correctly.
[email protected]979ad592012-07-12 16:42:1994 Browser* otr_browser = ui_test_utils::OpenURLOffTheRecord(
[email protected]ff8efd312011-03-21 17:33:5995 browser()->profile(),
96 GURL("chrome-extension://gbmgkahjioeacddebbnengilkgbkhodg/index.html"));
[email protected]b6987e02013-01-04 18:30:4397 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
[email protected]47ae23372013-01-29 01:50:4898 otr_browser->tab_strip_model()->GetActiveWebContents(),
[email protected]06bc5d92013-01-02 22:44:1399 "window.domAutomationController.send(document.title)",
[email protected]ff8efd312011-03-21 17:33:59100 &result));
101 EXPECT_EQ(result, "Loaded");
102
103 // Verify that the an extension can't load chrome://extension-icon icons
104 // without the management permission.
105 ui_test_utils::OpenURLOffTheRecord(
106 browser()->profile(),
107 GURL("chrome-extension://apocjbpjpkghdepdngjlknfpmabcmlao/index.html"));
[email protected]b6987e02013-01-04 18:30:43108 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
[email protected]47ae23372013-01-29 01:50:48109 otr_browser->tab_strip_model()->GetActiveWebContents(),
[email protected]06bc5d92013-01-02 22:44:13110 "window.domAutomationController.send(document.title)",
[email protected]ff8efd312011-03-21 17:33:59111 &result));
112 EXPECT_EQ(result, "Not Loaded");
113}