Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "grit/theme_resources.h" | |
| 28 #include "ui/base/resource/resource_bundle.h" | |
| 27 #include "ui/gfx/rect.h" | 29 #include "ui/gfx/rect.h" |
| 28 #include "ui/gfx/size.h" | 30 #include "ui/gfx/size.h" |
| 31 #include "ui/gfx/image/image_skia.h" | |
| 32 #include "ui/gfx/image/image_skia_operations.h" | |
| 33 #include "ui/gfx/skia_util.h" | |
| 29 | 34 |
| 30 using content::WebContents; | 35 using content::WebContents; |
| 31 using extensions::Extension; | 36 using extensions::Extension; |
| 32 | 37 |
| 38 namespace { | |
| 39 | |
| 40 // Views implementation of browser action button will return icon with set | |
| 41 // background. | |
| 42 gfx::ImageSkia AddBackgroundForViews(const gfx::ImageSkia& icon) { | |
| 43 #if defined(TOOLKIT_VIEWS) | |
| 44 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 45 gfx::ImageSkia bg = *rb.GetImageSkiaNamed(IDR_BROWSER_ACTION); | |
| 46 return gfx::ImageSkiaOperations::CreateSuperimposedImage(bg, icon); | |
| 47 #endif | |
| 48 | |
| 49 return icon; | |
| 50 } | |
| 51 | |
| 52 bool ImagesAreEqual(const gfx::ImageSkia& i1, const gfx::ImageSkia& i2) { | |
| 53 SkBitmap bitmap1 = | |
| 54 i1.GetRepresentation(ui::SCALE_FACTOR_100P).sk_bitmap(); | |
| 55 SkBitmap bitmap2 = | |
| 56 i2.GetRepresentation(ui::SCALE_FACTOR_100P).sk_bitmap(); | |
| 57 return gfx::BitmapsAreEqual(bitmap1, bitmap2); | |
| 58 } | |
| 59 | |
| 33 class BrowserActionApiTest : public ExtensionApiTest { | 60 class BrowserActionApiTest : public ExtensionApiTest { |
| 34 public: | 61 public: |
| 35 BrowserActionApiTest() {} | 62 BrowserActionApiTest() {} |
| 36 virtual ~BrowserActionApiTest() {} | 63 virtual ~BrowserActionApiTest() {} |
| 37 | 64 |
| 38 protected: | 65 protected: |
| 39 BrowserActionTestUtil GetBrowserActionsBar() { | 66 BrowserActionTestUtil GetBrowserActionsBar() { |
| 40 return BrowserActionTestUtil(browser()); | 67 return BrowserActionTestUtil(browser()); |
| 41 } | 68 } |
| 42 | 69 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 | 122 |
| 96 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) { | 123 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) { |
| 97 ASSERT_TRUE(RunExtensionTest("browser_action/no_icon")) << message_; | 124 ASSERT_TRUE(RunExtensionTest("browser_action/no_icon")) << message_; |
| 98 const Extension* extension = GetSingleLoadedExtension(); | 125 const Extension* extension = GetSingleLoadedExtension(); |
| 99 ASSERT_TRUE(extension) << message_; | 126 ASSERT_TRUE(extension) << message_; |
| 100 | 127 |
| 101 // Test that there is a browser action in the toolbar. | 128 // Test that there is a browser action in the toolbar. |
| 102 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions()); | 129 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions()); |
| 103 EXPECT_TRUE(GetBrowserActionsBar().HasIcon(0)); | 130 EXPECT_TRUE(GetBrowserActionsBar().HasIcon(0)); |
| 104 | 131 |
| 105 // Set prev_id which holds the id of the previous image, and use it in the | 132 gfx::Image action_icon = extension->browser_action()->GetIcon(0); |
| 106 // next test to see if the image changes. | 133 uint32_t action_icon_last_id = action_icon.AsBitmap().getGenerationID(); |
|
Jeffrey Yasskin
2012/08/21 20:10:38
It might be nice to have one sanity-check here, of
tbarzic
2012/08/22 00:12:49
Done.
| |
| 107 uint32_t prev_id = extension->browser_action()->GetIcon(0). | 134 uint32_t action_icon_current_id = 0; |
| 108 ToSkBitmap()->getGenerationID(); | 135 |
| 136 | |
| 137 ResultCatcher catcher; | |
| 109 | 138 |
| 110 // Tell the extension to update the icon using setIcon({imageData:...}). | 139 // Tell the extension to update the icon using setIcon({imageData:...}). |
| 111 ResultCatcher catcher; | 140 GetBrowserActionsBar().Press(0); |
| 112 ui_test_utils::NavigateToURL(browser(), | |
| 113 GURL(extension->GetResourceURL("update.html"))); | |
| 114 ASSERT_TRUE(catcher.GetNextResult()); | 141 ASSERT_TRUE(catcher.GetNextResult()); |
| 115 | 142 |
| 116 // Test that we received the changes. | 143 action_icon = extension->browser_action()->GetIcon(0); |
| 117 EXPECT_TRUE(GetBrowserActionsBar().HasIcon(0)); | 144 |
| 118 EXPECT_NE(prev_id, | 145 action_icon_current_id = action_icon.AsBitmap().getGenerationID(); |
| 119 extension->browser_action()->GetIcon(0). | 146 EXPECT_GT(action_icon_current_id, action_icon_last_id); |
| 120 ToSkBitmap()->getGenerationID()); | 147 action_icon_last_id = action_icon_current_id; |
| 121 prev_id = extension->browser_action()->GetIcon(0). | 148 |
| 122 ToSkBitmap()->getGenerationID(); | 149 EXPECT_FALSE( |
| 150 action_icon.AsImageSkia().HasRepresentation(ui::SCALE_FACTOR_200P)); | |
| 151 | |
| 152 EXPECT_TRUE(ImagesAreEqual(AddBackgroundForViews(action_icon.AsImageSkia()), | |
| 153 GetBrowserActionsBar().GetIcon(0).AsImageSkia())); | |
| 123 | 154 |
| 124 // Tell the extension to update the icon using setIcon({path:...}). | 155 // Tell the extension to update the icon using setIcon({path:...}). |
| 125 ui_test_utils::NavigateToURL(browser(), | 156 GetBrowserActionsBar().Press(0); |
| 126 GURL(extension->GetResourceURL("update2.html"))); | |
| 127 ASSERT_TRUE(catcher.GetNextResult()); | 157 ASSERT_TRUE(catcher.GetNextResult()); |
| 128 EXPECT_TRUE(GetBrowserActionsBar().HasIcon(0)); | 158 |
| 129 EXPECT_NE(prev_id, | 159 action_icon = extension->browser_action()->GetIcon(0); |
| 130 extension->browser_action()->GetIcon(0). | 160 |
| 131 ToSkBitmap()->getGenerationID()); | 161 action_icon_current_id = action_icon.AsBitmap().getGenerationID(); |
| 162 EXPECT_GT(action_icon_current_id, action_icon_last_id); | |
| 163 action_icon_last_id = action_icon_current_id; | |
| 164 | |
| 165 EXPECT_FALSE( | |
| 166 action_icon.AsImageSkia().HasRepresentation(ui::SCALE_FACTOR_200P)); | |
| 167 | |
| 168 EXPECT_TRUE(ImagesAreEqual(AddBackgroundForViews(action_icon.AsImageSkia()), | |
| 169 GetBrowserActionsBar().GetIcon(0).AsImageSkia())); | |
| 170 | |
| 171 // Tell the extension to update the icon using setIcon({imageDataSet:...}). | |
| 172 GetBrowserActionsBar().Press(0); | |
| 173 ASSERT_TRUE(catcher.GetNextResult()); | |
| 174 | |
| 175 action_icon = extension->browser_action()->GetIcon(0); | |
| 176 | |
| 177 action_icon_current_id = action_icon.AsBitmap().getGenerationID(); | |
| 178 EXPECT_GT(action_icon_current_id, action_icon_last_id); | |
| 179 action_icon_last_id = action_icon_current_id; | |
| 180 | |
| 181 EXPECT_TRUE( | |
| 182 action_icon.AsImageSkia().HasRepresentation(ui::SCALE_FACTOR_200P)); | |
| 183 | |
| 184 EXPECT_TRUE(ImagesAreEqual(AddBackgroundForViews(action_icon.AsImageSkia()), | |
| 185 GetBrowserActionsBar().GetIcon(0).AsImageSkia())); | |
| 186 | |
| 187 // Tell the extension to update the icon using setIcon({pathSet:...}). | |
| 188 GetBrowserActionsBar().Press(0); | |
| 189 ASSERT_TRUE(catcher.GetNextResult()); | |
| 190 | |
| 191 action_icon = extension->browser_action()->GetIcon(0); | |
| 192 | |
| 193 action_icon_current_id = action_icon.AsBitmap().getGenerationID(); | |
| 194 EXPECT_GT(action_icon_current_id, action_icon_last_id); | |
| 195 action_icon_last_id = action_icon_current_id; | |
| 196 | |
| 197 EXPECT_TRUE( | |
| 198 action_icon.AsImageSkia().HasRepresentation(ui::SCALE_FACTOR_200P)); | |
| 199 | |
| 200 EXPECT_TRUE(ImagesAreEqual(AddBackgroundForViews(action_icon.AsImageSkia()), | |
| 201 GetBrowserActionsBar().GetIcon(0).AsImageSkia())); | |
| 202 | |
| 203 // Tell the extension to update the icon using setIcon({imageDataSet:...}), | |
| 204 // but setting only size 19. | |
| 205 GetBrowserActionsBar().Press(0); | |
| 206 ASSERT_TRUE(catcher.GetNextResult()); | |
| 207 | |
| 208 action_icon = extension->browser_action()->GetIcon(0); | |
| 209 | |
| 210 action_icon_current_id = action_icon.AsBitmap().getGenerationID(); | |
| 211 EXPECT_GT(action_icon_current_id, action_icon_last_id); | |
| 212 action_icon_last_id = action_icon_current_id; | |
| 213 | |
| 214 EXPECT_FALSE( | |
| 215 action_icon.AsImageSkia().HasRepresentation(ui::SCALE_FACTOR_200P)); | |
| 216 | |
| 217 EXPECT_TRUE(ImagesAreEqual(AddBackgroundForViews(action_icon.AsImageSkia()), | |
| 218 GetBrowserActionsBar().GetIcon(0).AsImageSkia())); | |
| 219 | |
| 220 // Tell the extension to update the icon using setIcon({pathSet:...}), but | |
| 221 // setting only size 19. | |
| 222 GetBrowserActionsBar().Press(0); | |
| 223 ASSERT_TRUE(catcher.GetNextResult()); | |
| 224 | |
| 225 action_icon = extension->browser_action()->GetIcon(0); | |
| 226 | |
| 227 action_icon_current_id = action_icon.AsBitmap().getGenerationID(); | |
| 228 EXPECT_GT(action_icon_current_id, action_icon_last_id); | |
| 229 action_icon_last_id = action_icon_current_id; | |
| 230 | |
| 231 EXPECT_FALSE( | |
| 232 action_icon.AsImageSkia().HasRepresentation(ui::SCALE_FACTOR_200P)); | |
| 233 | |
| 234 EXPECT_TRUE(ImagesAreEqual(AddBackgroundForViews(action_icon.AsImageSkia()), | |
| 235 GetBrowserActionsBar().GetIcon(0).AsImageSkia())); | |
| 132 } | 236 } |
| 133 | 237 |
| 134 // This test is flaky as per http://crbug.com/74557. | 238 // This test is flaky as per http://crbug.com/74557. |
| 135 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, | 239 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, |
| 136 DISABLED_TabSpecificBrowserActionState) { | 240 DISABLED_TabSpecificBrowserActionState) { |
| 137 ASSERT_TRUE(RunExtensionTest("browser_action/tab_specific_state")) << | 241 ASSERT_TRUE(RunExtensionTest("browser_action/tab_specific_state")) << |
| 138 message_; | 242 message_; |
| 139 const Extension* extension = GetSingleLoadedExtension(); | 243 const Extension* extension = GetSingleLoadedExtension(); |
| 140 ASSERT_TRUE(extension) << message_; | 244 ASSERT_TRUE(extension) << message_; |
| 141 | 245 |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 470 ResultCatcher catcher; | 574 ResultCatcher catcher; |
| 471 ui_test_utils::NavigateToURL(browser(), | 575 ui_test_utils::NavigateToURL(browser(), |
| 472 GURL(extension->GetResourceURL("update.html"))); | 576 GURL(extension->GetResourceURL("update.html"))); |
| 473 ASSERT_TRUE(catcher.GetNextResult()); | 577 ASSERT_TRUE(catcher.GetNextResult()); |
| 474 | 578 |
| 475 // Test the getters for a specific tab. | 579 // Test the getters for a specific tab. |
| 476 ui_test_utils::NavigateToURL(browser(), | 580 ui_test_utils::NavigateToURL(browser(), |
| 477 GURL(extension->GetResourceURL("update2.html"))); | 581 GURL(extension->GetResourceURL("update2.html"))); |
| 478 ASSERT_TRUE(catcher.GetNextResult()); | 582 ASSERT_TRUE(catcher.GetNextResult()); |
| 479 } | 583 } |
| 584 | |
| 585 } // namespace | |
| OLD | NEW |