| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2009 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 "chrome/browser/browser.h" | |
| 6 #include "chrome/browser/extensions/extension_error_reporter.h" | |
| 7 #include "chrome/browser/extensions/test_extension_loader.h" | |
| 8 #include "chrome/common/chrome_paths.h" | |
| 9 #include "chrome/test/in_process_browser_test.h" | |
| 10 #include "chrome/test/ui_test_utils.h" | |
| 11 #include "net/base/net_util.h" | |
| 12 | |
| 13 namespace { | |
| 14 | |
| 15 // The extension we're using as our test case. | |
| 16 const char* kExtensionId = "00123456789abcdef0123456789abcdef0123456"; | |
| 17 | |
| 18 } // namespace | |
| 19 | |
| 20 class ExtensionContentScriptInjectTest : public InProcessBrowserTest { | |
| 21 public: | |
| 22 virtual void SetUp() { | |
| 23 // Initialize the error reporter here, otherwise BrowserMain will create it | |
| 24 // with the wrong MessageLoop. | |
| 25 ExtensionErrorReporter::Init(false); | |
| 26 | |
| 27 InProcessBrowserTest::SetUp(); | |
| 28 } | |
| 29 }; | |
| 30 | |
| 31 // Tests that an extension's user script gets injected into content. | |
| 32 IN_PROC_BROWSER_TEST_F(ExtensionContentScriptInjectTest, Simple) { | |
| 33 // Get the path to our extension. | |
| 34 FilePath extension_path; | |
| 35 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extension_path)); | |
| 36 extension_path = extension_path.AppendASCII("extensions"). | |
| 37 AppendASCII("content_script_inject"); | |
| 38 ASSERT_TRUE(file_util::DirectoryExists(extension_path)); // sanity check | |
| 39 | |
| 40 // Load it. | |
| 41 TestExtensionLoader loader(browser()->profile()); | |
| 42 Extension* extension = loader.Load(kExtensionId, extension_path); | |
| 43 ASSERT_TRUE(extension); | |
| 44 | |
| 45 // Get the file URL to our test page. | |
| 46 FilePath test_page_path; | |
| 47 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_page_path)); | |
| 48 test_page_path = test_page_path.AppendASCII("extensions"). | |
| 49 AppendASCII("content_script_inject_page.html"); | |
| 50 ASSERT_TRUE(file_util::PathExists(test_page_path)); // sanity check | |
| 51 GURL test_page_url = net::FilePathToFileURL(test_page_path); | |
| 52 | |
| 53 ui_test_utils::NavigateToURL(browser(), test_page_url); | |
| 54 TabContents* tabContents = browser()->GetSelectedTabContents(); | |
| 55 | |
| 56 // The injected user script will set the page title upon execution. | |
| 57 const char kExpectedTitle[] = | |
| 58 "testScriptFilesRunInSameContext,testContentInteraction," | |
| 59 "testCSSWasInjected,testCannotSeeOtherContentScriptGlobals," | |
| 60 "testRunAtDocumentStart,testGotLoadEvents,"; | |
| 61 EXPECT_EQ(ASCIIToUTF16(kExpectedTitle), tabContents->GetTitle()); | |
| 62 } | |
| OLD | NEW |