blob: f77be4618a012e90f2cc17776d73f642c993cb4b [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]d8748142012-05-16 21:13:4310#include "chrome/browser/ui/browser_finder.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]f83773f2011-03-02 19:15:2114#include "googleurl/src/gurl.h"
15#include "net/base/mock_host_resolver.h"
16
17class ExtensionIconSourceTest : public ExtensionApiTest {
[email protected]39daa022011-12-07 21:16:2218 protected:
19 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
20 ExtensionApiTest::SetUpCommandLine(command_line);
21 command_line->AppendSwitch(switches::kAllowLegacyExtensionManifests);
22 }
[email protected]f83773f2011-03-02 19:15:2123};
24
25IN_PROC_BROWSER_TEST_F(ExtensionIconSourceTest, IconsLoaded) {
26 FilePath basedir = test_data_dir_.AppendASCII("icons");
27 ASSERT_TRUE(LoadExtension(basedir.AppendASCII("extension_with_permission")));
28 ASSERT_TRUE(LoadExtension(basedir.AppendASCII("extension_no_permission")));
29 std::string result;
30
31 // Test that the icons are loaded and that the chrome://extension-icon
32 // parameters work correctly.
33 ui_test_utils::NavigateToURL(
34 browser(),
35 GURL("chrome-extension://gbmgkahjioeacddebbnengilkgbkhodg/index.html"));
36 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString(
[email protected]4ca15302012-01-03 05:53:2037 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"",
[email protected]f83773f2011-03-02 19:15:2138 L"window.domAutomationController.send(document.title)",
39 &result));
40 EXPECT_EQ(result, "Loaded");
41
42 // Verify that the an extension can't load chrome://extension-icon icons
43 // without the management permission.
44 ui_test_utils::NavigateToURL(
45 browser(),
46 GURL("chrome-extension://apocjbpjpkghdepdngjlknfpmabcmlao/index.html"));
47 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString(
[email protected]4ca15302012-01-03 05:53:2048 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"",
[email protected]f83773f2011-03-02 19:15:2149 L"window.domAutomationController.send(document.title)",
50 &result));
51 EXPECT_EQ(result, "Not Loaded");
52}
[email protected]ff8efd312011-03-21 17:33:5953
54IN_PROC_BROWSER_TEST_F(ExtensionIconSourceTest, IconsLoadedIncognito) {
55 FilePath basedir = test_data_dir_.AppendASCII("icons");
56 ASSERT_TRUE(LoadExtensionIncognito(
57 basedir.AppendASCII("extension_with_permission")));
58 ASSERT_TRUE(LoadExtensionIncognito(
59 basedir.AppendASCII("extension_no_permission")));
60 std::string result;
61
62 // Test that the icons are loaded and that the chrome://extension-icon
63 // parameters work correctly.
64 ui_test_utils::OpenURLOffTheRecord(
65 browser()->profile(),
66 GURL("chrome-extension://gbmgkahjioeacddebbnengilkgbkhodg/index.html"));
[email protected]d8748142012-05-16 21:13:4367 Browser* otr_browser = browser::FindTabbedBrowser(
[email protected]b35b26b32011-05-05 20:35:1468 browser()->profile()->GetOffTheRecordProfile(), false);
[email protected]ff8efd312011-03-21 17:33:5969 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString(
[email protected]4ca15302012-01-03 05:53:2070 otr_browser->GetSelectedWebContents()->GetRenderViewHost(), L"",
[email protected]ff8efd312011-03-21 17:33:5971 L"window.domAutomationController.send(document.title)",
72 &result));
73 EXPECT_EQ(result, "Loaded");
74
75 // Verify that the an extension can't load chrome://extension-icon icons
76 // without the management permission.
77 ui_test_utils::OpenURLOffTheRecord(
78 browser()->profile(),
79 GURL("chrome-extension://apocjbpjpkghdepdngjlknfpmabcmlao/index.html"));
80 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString(
[email protected]4ca15302012-01-03 05:53:2081 otr_browser->GetSelectedWebContents()->GetRenderViewHost(), L"",
[email protected]ff8efd312011-03-21 17:33:5982 L"window.domAutomationController.send(document.title)",
83 &result));
84 EXPECT_EQ(result, "Not Loaded");
85}