Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(332)

Side by Side Diff: chrome/browser/extensions/api/extension_action/browser_action_apitest.cc

Issue 10855154: Update browserAction.setIcon and pageAction.setIcon for hidpi (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #if defined(TOOLKIT_GTK) 7 #if defined(TOOLKIT_GTK)
8 #include <gtk/gtk.h> 8 #include <gtk/gtk.h>
9 #endif 9 #endif
10 10
11 #include "chrome/browser/extensions/browser_action_test_util.h" 11 #include "chrome/browser/extensions/browser_action_test_util.h"
12 #include "chrome/browser/extensions/extension_apitest.h" 12 #include "chrome/browser/extensions/extension_apitest.h"
13 #include "chrome/browser/extensions/extension_service.h" 13 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/extensions/extension_tab_util.h" 14 #include "chrome/browser/extensions/extension_tab_util.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/browser_commands.h" 17 #include "chrome/browser/ui/browser_commands.h"
18 #include "chrome/browser/ui/browser_tabstrip.h" 18 #include "chrome/browser/ui/browser_tabstrip.h"
19 #include "chrome/browser/ui/browser_window.h" 19 #include "chrome/browser/ui/browser_window.h"
20 #include "chrome/common/chrome_notification_types.h" 20 #include "chrome/common/chrome_notification_types.h"
21 #include "chrome/common/extensions/extension_action.h" 21 #include "chrome/common/extensions/extension_action.h"
22 #include "chrome/common/url_constants.h" 22 #include "chrome/common/url_constants.h"
23 #include "chrome/test/base/ui_test_utils.h" 23 #include "chrome/test/base/ui_test_utils.h"
24 #include "content/public/browser/notification_service.h" 24 #include "content/public/browser/notification_service.h"
25 #include "content/public/browser/web_contents.h" 25 #include "content/public/browser/web_contents.h"
26 #include "content/public/test/browser_test_utils.h" 26 #include "content/public/test/browser_test_utils.h"
27 #include "ui/gfx/rect.h" 27 #include "ui/gfx/rect.h"
28 #include "ui/gfx/size.h" 28 #include "ui/gfx/size.h"
29 #include "ui/gfx/image/image_skia.h"
29 30
30 using content::WebContents; 31 using content::WebContents;
31 using extensions::Extension; 32 using extensions::Extension;
32 33
33 class BrowserActionApiTest : public ExtensionApiTest { 34 class BrowserActionApiTest : public ExtensionApiTest {
34 public: 35 public:
35 BrowserActionApiTest() {} 36 BrowserActionApiTest() {}
36 virtual ~BrowserActionApiTest() {} 37 virtual ~BrowserActionApiTest() {}
37 38
38 protected: 39 protected:
39 BrowserActionTestUtil GetBrowserActionsBar() { 40 BrowserActionTestUtil GetBrowserActionsBar() {
40 return BrowserActionTestUtil(browser()); 41 return BrowserActionTestUtil(browser());
41 } 42 }
42 43
43 bool OpenPopup(int index) { 44 bool OpenPopup(int index) {
44 ResultCatcher catcher; 45 ResultCatcher catcher;
45 content::WindowedNotificationObserver popup_observer( 46 content::WindowedNotificationObserver popup_observer(
46 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, 47 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
47 content::NotificationService::AllSources()); 48 content::NotificationService::AllSources());
48 GetBrowserActionsBar().Press(index); 49 GetBrowserActionsBar().Press(index);
49 popup_observer.Wait(); 50 popup_observer.Wait();
50 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 51 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
51 return GetBrowserActionsBar().HasPopup(); 52 return GetBrowserActionsBar().HasPopup();
52 } 53 }
54
55 // Verifies that icons gotten from actions bar and browser action have
56 // changed. Also checks if action icon has icon representation for 2x as
57 // expected.
58 void VerifyIconState(const Extension* extension,
Jeffrey Yasskin 2012/08/17 23:20:28 Please use descriptive assertion names, so people
tbarzic 2012/08/21 00:22:07 ok, got rid of this function..
59 bool has_2x_icon,
60 uint32_t* last_bar_icon_id,
61 uint32_t* last_action_icon_id) {
62 gfx::ImageSkia action_icon =
63 extension->browser_action()->GetIcon(0).AsImageSkia();
64
65 EXPECT_EQ(has_2x_icon,
66 action_icon.HasRepresentation(ui::SCALE_FACTOR_200P));
67
68 SkBitmap action_icon_bitmap =
69 action_icon.GetRepresentation(ui::SCALE_FACTOR_100P).sk_bitmap();
70
71 uint32_t bar_icon_id = GetBrowserActionsBar().GetIconID(0);
72
73 if (*last_action_icon_id > 0)
74 EXPECT_GT(action_icon_bitmap.getGenerationID(), *last_action_icon_id);
Jeffrey Yasskin 2012/08/17 23:20:28 Please include a test that checks for icon equalit
tbarzic 2012/08/21 00:22:07 yeah, I've stumbled upon that function on Friday,
75 if (*last_bar_icon_id > 0)
76 EXPECT_GT(bar_icon_id, *last_bar_icon_id);
77
78 // Update last icon ids so we can test next icons' ids against current
79 // icons.
80 *last_action_icon_id = action_icon_bitmap.getGenerationID();
81 *last_bar_icon_id = bar_icon_id;
82 }
53 }; 83 };
54 84
55 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, Basic) { 85 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, Basic) {
56 ASSERT_TRUE(test_server()->Start()); 86 ASSERT_TRUE(test_server()->Start());
57 ASSERT_TRUE(RunExtensionTest("browser_action/basics")) << message_; 87 ASSERT_TRUE(RunExtensionTest("browser_action/basics")) << message_;
58 const Extension* extension = GetSingleLoadedExtension(); 88 const Extension* extension = GetSingleLoadedExtension();
59 ASSERT_TRUE(extension) << message_; 89 ASSERT_TRUE(extension) << message_;
60 90
61 // Test that there is a browser action in the toolbar. 91 // Test that there is a browser action in the toolbar.
62 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions()); 92 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 125
96 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) { 126 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) {
97 ASSERT_TRUE(RunExtensionTest("browser_action/no_icon")) << message_; 127 ASSERT_TRUE(RunExtensionTest("browser_action/no_icon")) << message_;
98 const Extension* extension = GetSingleLoadedExtension(); 128 const Extension* extension = GetSingleLoadedExtension();
99 ASSERT_TRUE(extension) << message_; 129 ASSERT_TRUE(extension) << message_;
100 130
101 // Test that there is a browser action in the toolbar. 131 // Test that there is a browser action in the toolbar.
102 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions()); 132 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions());
103 EXPECT_TRUE(GetBrowserActionsBar().HasIcon(0)); 133 EXPECT_TRUE(GetBrowserActionsBar().HasIcon(0));
104 134
105 // Set prev_id which holds the id of the previous image, and use it in the 135 uint32_t action_icon_last_id = 0;
106 // next test to see if the image changes. 136 uint32_t bar_icon_last_id = 0;
107 uint32_t prev_id = extension->browser_action()->GetIcon(0). 137
108 ToSkBitmap()->getGenerationID(); 138 ResultCatcher catcher;
139
140 // First, let's setup icon ids to some valid values..
141 GetBrowserActionsBar().Press(0);
142 ASSERT_TRUE(catcher.GetNextResult());
143
144 VerifyIconState(extension, false, &bar_icon_last_id, &action_icon_last_id);
109 145
110 // Tell the extension to update the icon using setIcon({imageData:...}). 146 // Tell the extension to update the icon using setIcon({imageData:...}).
111 ResultCatcher catcher; 147 GetBrowserActionsBar().Press(0);
112 ui_test_utils::NavigateToURL(browser(),
113 GURL(extension->GetResourceURL("update.html")));
114 ASSERT_TRUE(catcher.GetNextResult()); 148 ASSERT_TRUE(catcher.GetNextResult());
115 149
116 // Test that we received the changes. 150 VerifyIconState(extension, false, &bar_icon_last_id, &action_icon_last_id);
117 EXPECT_TRUE(GetBrowserActionsBar().HasIcon(0));
118 EXPECT_NE(prev_id,
119 extension->browser_action()->GetIcon(0).
120 ToSkBitmap()->getGenerationID());
121 prev_id = extension->browser_action()->GetIcon(0).
122 ToSkBitmap()->getGenerationID();
123 151
124 // Tell the extension to update the icon using setIcon({path:...}). 152 // Tell the extension to update the icon using setIcon({path:...}).
125 ui_test_utils::NavigateToURL(browser(), 153 GetBrowserActionsBar().Press(0);
126 GURL(extension->GetResourceURL("update2.html")));
127 ASSERT_TRUE(catcher.GetNextResult()); 154 ASSERT_TRUE(catcher.GetNextResult());
128 EXPECT_TRUE(GetBrowserActionsBar().HasIcon(0)); 155
129 EXPECT_NE(prev_id, 156 VerifyIconState(extension, false, &bar_icon_last_id, &action_icon_last_id);
130 extension->browser_action()->GetIcon(0). 157
131 ToSkBitmap()->getGenerationID()); 158 // Tell the extension to update the icon using setIcon({imageDataSet:...}).
159 GetBrowserActionsBar().Press(0);
160 ASSERT_TRUE(catcher.GetNextResult());
161
162 VerifyIconState(extension, true, &bar_icon_last_id, &action_icon_last_id);
163
164 // Tell the extension to update the icon using setIcon({pathSet:...}).
165 GetBrowserActionsBar().Press(0);
166 ASSERT_TRUE(catcher.GetNextResult());
167
168 VerifyIconState(extension, true, &bar_icon_last_id, &action_icon_last_id);
132 } 169 }
133 170
134 // This test is flaky as per http://crbug.com/74557. 171 // This test is flaky as per http://crbug.com/74557.
135 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, 172 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest,
136 DISABLED_TabSpecificBrowserActionState) { 173 DISABLED_TabSpecificBrowserActionState) {
137 ASSERT_TRUE(RunExtensionTest("browser_action/tab_specific_state")) << 174 ASSERT_TRUE(RunExtensionTest("browser_action/tab_specific_state")) <<
138 message_; 175 message_;
139 const Extension* extension = GetSingleLoadedExtension(); 176 const Extension* extension = GetSingleLoadedExtension();
140 ASSERT_TRUE(extension) << message_; 177 ASSERT_TRUE(extension) << message_;
141 178
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 ResultCatcher catcher; 507 ResultCatcher catcher;
471 ui_test_utils::NavigateToURL(browser(), 508 ui_test_utils::NavigateToURL(browser(),
472 GURL(extension->GetResourceURL("update.html"))); 509 GURL(extension->GetResourceURL("update.html")));
473 ASSERT_TRUE(catcher.GetNextResult()); 510 ASSERT_TRUE(catcher.GetNextResult());
474 511
475 // Test the getters for a specific tab. 512 // Test the getters for a specific tab.
476 ui_test_utils::NavigateToURL(browser(), 513 ui_test_utils::NavigateToURL(browser(),
477 GURL(extension->GetResourceURL("update2.html"))); 514 GURL(extension->GetResourceURL("update2.html")));
478 ASSERT_TRUE(catcher.GetNextResult()); 515 ASSERT_TRUE(catcher.GetNextResult());
479 } 516 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698