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/logging.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/browser_list.h" 11 #include "chrome/test/ui_test_utils.h" 12 #include "content/browser/tab_contents/tab_contents.h" 13 #include "googleurl/src/gurl.h" 14 #include "net/base/mock_host_resolver.h" 15 16 class ExtensionIconSourceTest : public ExtensionApiTest { 17 }; 18 19 IN_PROC_BROWSER_TEST_F(ExtensionIconSourceTest, IconsLoaded) { 20 FilePath basedir = test_data_dir_.AppendASCII("icons"); 21 ASSERT_TRUE(LoadExtension(basedir.AppendASCII("extension_with_permission"))); 22 ASSERT_TRUE(LoadExtension(basedir.AppendASCII("extension_no_permission"))); 23 std::string result; 24 25 // Test that the icons are loaded and that the chrome://extension-icon 26 // parameters work correctly. 27 ui_test_utils::NavigateToURL( 28 browser(), 29 GURL("chrome-extension://gbmgkahjioeacddebbnengilkgbkhodg/index.html")); 30 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( 31 browser()->GetSelectedTabContents()->render_view_host(), L"", 32 L"window.domAutomationController.send(document.title)", 33 &result)); 34 EXPECT_EQ(result, "Loaded"); 35 36 // Verify that the an extension can't load chrome://extension-icon icons 37 // without the management permission. 38 ui_test_utils::NavigateToURL( 39 browser(), 40 GURL("chrome-extension://apocjbpjpkghdepdngjlknfpmabcmlao/index.html")); 41 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( 42 browser()->GetSelectedTabContents()->render_view_host(), L"", 43 L"window.domAutomationController.send(document.title)", 44 &result)); 45 EXPECT_EQ(result, "Not Loaded"); 46 } 47 48 IN_PROC_BROWSER_TEST_F(ExtensionIconSourceTest, IconsLoadedIncognito) { 49 FilePath basedir = test_data_dir_.AppendASCII("icons"); 50 ASSERT_TRUE(LoadExtensionIncognito( 51 basedir.AppendASCII("extension_with_permission"))); 52 ASSERT_TRUE(LoadExtensionIncognito( 53 basedir.AppendASCII("extension_no_permission"))); 54 std::string result; 55 56 // Test that the icons are loaded and that the chrome://extension-icon 57 // parameters work correctly. 58 ui_test_utils::OpenURLOffTheRecord( 59 browser()->profile(), 60 GURL("chrome-extension://gbmgkahjioeacddebbnengilkgbkhodg/index.html")); 61 Browser* otr_browser = BrowserList::FindBrowserWithType( 62 browser()->profile()->GetOffTheRecordProfile(), Browser::TYPE_NORMAL, 63 false); 64 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( 65 otr_browser->GetSelectedTabContents()->render_view_host(), L"", 66 L"window.domAutomationController.send(document.title)", 67 &result)); 68 EXPECT_EQ(result, "Loaded"); 69 70 // Verify that the an extension can't load chrome://extension-icon icons 71 // without the management permission. 72 ui_test_utils::OpenURLOffTheRecord( 73 browser()->profile(), 74 GURL("chrome-extension://apocjbpjpkghdepdngjlknfpmabcmlao/index.html")); 75 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( 76 otr_browser->GetSelectedTabContents()->render_view_host(), L"", 77 L"window.domAutomationController.send(document.title)", 78 &result)); 79 EXPECT_EQ(result, "Not Loaded"); 80 } 81