OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/browser.h" | 5 #include "chrome/browser/browser.h" |
6 #include "chrome/browser/browser_window.h" | 6 #include "chrome/browser/browser_window.h" |
7 #include "chrome/browser/extensions/extension_apitest.h" | 7 #include "chrome/browser/extensions/extension_apitest.h" |
8 #include "chrome/browser/extensions/extension_browser_event_router.h" | 8 #include "chrome/browser/extensions/extension_browser_event_router.h" |
9 #include "chrome/browser/extensions/extension_tabs_module.h" | 9 #include "chrome/browser/extensions/extension_tabs_module.h" |
10 #include "chrome/browser/extensions/extensions_service.h" | 10 #include "chrome/browser/extensions/extensions_service.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 // Test that we received the changes. | 35 // Test that we received the changes. |
36 int tab_id = | 36 int tab_id = |
37 browser()->GetSelectedTabContents()->controller().session_id().id(); | 37 browser()->GetSelectedTabContents()->controller().session_id().id(); |
38 ExtensionAction* action = extension->page_action(); | 38 ExtensionAction* action = extension->page_action(); |
39 ASSERT_TRUE(action); | 39 ASSERT_TRUE(action); |
40 EXPECT_EQ("Modified", action->GetTitle(tab_id)); | 40 EXPECT_EQ("Modified", action->GetTitle(tab_id)); |
41 | 41 |
42 { | 42 { |
43 // Simulate the page action being clicked. | 43 // Simulate the page action being clicked. |
44 ResultCatcher catcher; | 44 ResultCatcher catcher; |
45 int tab_id = ExtensionTabUtil::GetTabId(browser()->GetSelectedTabContents())
; | 45 int tab_id = |
| 46 ExtensionTabUtil::GetTabId(browser()->GetSelectedTabContents()); |
46 ExtensionBrowserEventRouter::GetInstance()->PageActionExecuted( | 47 ExtensionBrowserEventRouter::GetInstance()->PageActionExecuted( |
47 browser()->profile(), extension->id(), "", tab_id, "", 0); | 48 browser()->profile(), extension->id(), "", tab_id, "", 0); |
48 EXPECT_TRUE(catcher.GetNextResult()); | 49 EXPECT_TRUE(catcher.GetNextResult()); |
49 } | 50 } |
50 | 51 |
51 { | 52 { |
52 // Tell the extension to update the page action state again. | 53 // Tell the extension to update the page action state again. |
53 ResultCatcher catcher; | 54 ResultCatcher catcher; |
54 ui_test_utils::NavigateToURL(browser(), | 55 ui_test_utils::NavigateToURL(browser(), |
55 GURL(extension->GetResourceURL("update2.html"))); | 56 GURL(extension->GetResourceURL("update2.html"))); |
56 ASSERT_TRUE(catcher.GetNextResult()); | 57 ASSERT_TRUE(catcher.GetNextResult()); |
57 } | 58 } |
58 | 59 |
59 // Test that we received the changes. | 60 // Test that we received the changes. |
60 tab_id = browser()->GetSelectedTabContents()->controller().session_id().id(); | 61 tab_id = browser()->GetSelectedTabContents()->controller().session_id().id(); |
61 EXPECT_FALSE(action->GetIcon(tab_id).isNull()); | 62 EXPECT_FALSE(action->GetIcon(tab_id).isNull()); |
62 } | 63 } |
| 64 |
| 65 |
| 66 // Tests old-style pageActions API that is deprecated but we don't want to |
| 67 // break. |
| 68 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, OldPageActions) { |
| 69 ASSERT_TRUE(RunExtensionTest("old_page_actions")) << message_; |
| 70 |
| 71 ExtensionsService* service = browser()->profile()->GetExtensionsService(); |
| 72 ASSERT_EQ(1u, service->extensions()->size()); |
| 73 Extension* extension = service->extensions()->at(0); |
| 74 ASSERT_TRUE(extension); |
| 75 |
| 76 // Have the extension enable the page action. |
| 77 { |
| 78 ResultCatcher catcher; |
| 79 ui_test_utils::NavigateToURL(browser(), |
| 80 GURL(extension->GetResourceURL("page.html"))); |
| 81 ASSERT_TRUE(catcher.GetNextResult()); |
| 82 } |
| 83 |
| 84 // Simulate the page action being clicked. |
| 85 { |
| 86 ResultCatcher catcher; |
| 87 int tab_id = |
| 88 ExtensionTabUtil::GetTabId(browser()->GetSelectedTabContents()); |
| 89 ExtensionBrowserEventRouter::GetInstance()->PageActionExecuted( |
| 90 browser()->profile(), extension->id(), "action", tab_id, "", 1); |
| 91 EXPECT_TRUE(catcher.GetNextResult()); |
| 92 } |
| 93 } |
| 94 |
OLD | NEW |