OLD | NEW |
(Empty) | |
| 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 "chrome/browser/extensions/extension_action.h" |
| 6 #include "chrome/browser/extensions/extension_action_manager.h" |
| 7 #include "chrome/browser/extensions/extension_apitest.h" |
| 8 #include "chrome/browser/extensions/extension_tab_util.h" |
| 9 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 10 #include "chrome/browser/ui/browser_tabstrip.h" |
| 11 #include "chrome/common/extensions/features/feature.h" |
| 12 #include "content/public/test/browser_test_utils.h" |
| 13 |
| 14 namespace extensions { |
| 15 namespace { |
| 16 |
| 17 class DeclarativeContentApiTest : public ExtensionApiTest { |
| 18 public: |
| 19 DeclarativeContentApiTest() |
| 20 // Set the channel to "trunk" since declarativeContent is restricted |
| 21 // to trunk. |
| 22 : current_channel_(chrome::VersionInfo::CHANNEL_UNKNOWN) { |
| 23 } |
| 24 virtual ~DeclarativeContentApiTest() {} |
| 25 |
| 26 extensions::Feature::ScopedCurrentChannel current_channel_; |
| 27 }; |
| 28 |
| 29 IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest, Overview) { |
| 30 ExtensionTestMessageListener ready("ready", true); |
| 31 const Extension* extension = |
| 32 LoadExtension(test_data_dir_.AppendASCII("declarative_content/overview")); |
| 33 ASSERT_TRUE(extension); |
| 34 const ExtensionAction* page_action = |
| 35 ExtensionActionManager::Get(browser()->profile())-> |
| 36 GetPageAction(*extension); |
| 37 ASSERT_TRUE(page_action); |
| 38 |
| 39 ASSERT_TRUE(ready.WaitUntilSatisfied()); |
| 40 content::WebContents* const tab = chrome::GetWebContentsAt(browser(), 0); |
| 41 const int tab_id = ExtensionTabUtil::GetTabId(tab); |
| 42 |
| 43 NavigateInRenderer(tab, GURL("http://test1/")); |
| 44 |
| 45 // The declarative API should show the page action instantly, rather |
| 46 // than waiting for the extension to run. |
| 47 EXPECT_TRUE(page_action->GetIsVisible(tab_id)); |
| 48 |
| 49 // Make sure leaving a matching page unshows the page action. |
| 50 NavigateInRenderer(tab, GURL("http://not_checked/")); |
| 51 EXPECT_FALSE(page_action->GetIsVisible(tab_id)); |
| 52 |
| 53 // Insert a password field to make sure that's noticed. |
| 54 ASSERT_TRUE(content::ExecuteJavaScript( |
| 55 tab->GetRenderViewHost(), L"", |
| 56 L"document.body.innerHTML = '<input type=\"password\">';")); |
| 57 // Give the mutation observer a chance to run and send back the |
| 58 // matching-selector update. |
| 59 ASSERT_TRUE(content::ExecuteJavaScript( |
| 60 tab->GetRenderViewHost(), L"", L"")); |
| 61 EXPECT_TRUE(page_action->GetIsVisible(tab_id)); |
| 62 |
| 63 // Remove it again to make sure that reverts the action. |
| 64 ASSERT_TRUE(content::ExecuteJavaScript( |
| 65 tab->GetRenderViewHost(), L"", |
| 66 L"document.body.innerHTML = 'Hello world';")); |
| 67 // Give the mutation observer a chance to run and send back the |
| 68 // matching-selector update. |
| 69 ASSERT_TRUE(content::ExecuteJavaScript( |
| 70 tab->GetRenderViewHost(), L"", L"")); |
| 71 EXPECT_FALSE(page_action->GetIsVisible(tab_id)); |
| 72 } |
| 73 |
| 74 } // namespace |
| 75 } // namespace extensions |
OLD | NEW |