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" |
11 #include "chrome/browser/profile.h" | 11 #include "chrome/browser/profile.h" |
12 #include "chrome/browser/tab_contents/tab_contents.h" | 12 #include "chrome/browser/tab_contents/tab_contents.h" |
13 #include "chrome/browser/views/browser_actions_container.h" | 13 #include "chrome/browser/views/browser_actions_container.h" |
14 #include "chrome/browser/views/toolbar_view.h" | 14 #include "chrome/browser/views/toolbar_view.h" |
15 #include "chrome/common/extensions/extension_action.h" | 15 #include "chrome/common/extensions/extension_action2.h" |
16 #include "chrome/test/ui_test_utils.h" | 16 #include "chrome/test/ui_test_utils.h" |
17 | 17 |
18 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PageAction) { | 18 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PageAction) { |
19 StartHTTPServer(); | 19 StartHTTPServer(); |
20 ASSERT_TRUE(RunExtensionTest("page_action")) << message_; | 20 ASSERT_TRUE(RunExtensionTest("page_action")) << message_; |
21 | 21 |
22 ExtensionsService* service = browser()->profile()->GetExtensionsService(); | 22 ExtensionsService* service = browser()->profile()->GetExtensionsService(); |
23 ASSERT_EQ(1u, service->extensions()->size()); | 23 ASSERT_EQ(1u, service->extensions()->size()); |
24 Extension* extension = service->extensions()->at(0); | 24 Extension* extension = service->extensions()->at(0); |
25 ASSERT_TRUE(extension); | 25 ASSERT_TRUE(extension); |
26 | 26 |
27 { | 27 { |
28 // Tell the extension to update the page action state. | 28 // Tell the extension to update the page action state. |
29 ResultCatcher catcher; | 29 ResultCatcher catcher; |
30 ui_test_utils::NavigateToURL(browser(), | 30 ui_test_utils::NavigateToURL(browser(), |
31 GURL(extension->GetResourceURL("update.html"))); | 31 GURL(extension->GetResourceURL("update.html"))); |
32 ASSERT_TRUE(catcher.GetNextResult()); | 32 ASSERT_TRUE(catcher.GetNextResult()); |
33 } | 33 } |
34 | 34 |
35 // Test that we received the changes. | 35 // Test that we received the changes. |
36 const ExtensionActionState* action_state = | 36 int tab_id = |
37 browser()->GetSelectedTabContents()->GetPageActionState( | 37 browser()->GetSelectedTabContents()->controller().session_id().id(); |
38 extension->page_action()); | 38 ExtensionAction2* action = extension->page_action(); |
39 ASSERT_TRUE(action_state); | 39 ASSERT_TRUE(action); |
40 EXPECT_EQ("Modified", action_state->title()); | 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 = ExtensionTabUtil::GetTabId(browser()->GetSelectedTabContents())
; |
46 ExtensionBrowserEventRouter::GetInstance()->PageActionExecuted( | 46 ExtensionBrowserEventRouter::GetInstance()->PageActionExecuted( |
47 browser()->profile(), extension->id(), "", tab_id, "", 0); | 47 browser()->profile(), extension->id(), "", tab_id, "", 0); |
48 EXPECT_TRUE(catcher.GetNextResult()); | 48 EXPECT_TRUE(catcher.GetNextResult()); |
49 } | 49 } |
50 | 50 |
51 { | 51 { |
52 // Tell the extension to update the page action state again. | 52 // Tell the extension to update the page action state again. |
53 ResultCatcher catcher; | 53 ResultCatcher catcher; |
54 ui_test_utils::NavigateToURL(browser(), | 54 ui_test_utils::NavigateToURL(browser(), |
55 GURL(extension->GetResourceURL("update2.html"))); | 55 GURL(extension->GetResourceURL("update2.html"))); |
56 ASSERT_TRUE(catcher.GetNextResult()); | 56 ASSERT_TRUE(catcher.GetNextResult()); |
57 } | 57 } |
58 | 58 |
59 // Test that we received the changes. | 59 // Test that we received the changes. |
60 action_state = browser()->GetSelectedTabContents()->GetPageActionState( | 60 tab_id = browser()->GetSelectedTabContents()->controller().session_id().id(); |
61 extension->page_action()); | 61 EXPECT_FALSE(action->GetIcon(tab_id).isNull()); |
62 EXPECT_TRUE(action_state->icon()); | |
63 } | 62 } |
OLD | NEW |