| 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 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" | 6 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
| 7 #include "chrome/browser/extensions/browser_action_test_util.h" | 7 #include "chrome/browser/extensions/browser_action_test_util.h" |
| 8 #include "chrome/browser/extensions/extension_action.h" | 8 #include "chrome/browser/extensions/extension_action.h" |
| 9 #include "chrome/browser/extensions/extension_action_icon_factory.h" | 9 #include "chrome/browser/extensions/extension_action_icon_factory.h" |
| 10 #include "chrome/browser/extensions/extension_action_manager.h" | 10 #include "chrome/browser/extensions/extension_action_manager.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 SkBitmap bitmap2 = i2.GetRepresentation(scale).sk_bitmap(); | 66 SkBitmap bitmap2 = i2.GetRepresentation(scale).sk_bitmap(); |
| 67 return gfx::BitmapsAreEqual(bitmap1, bitmap2); | 67 return gfx::BitmapsAreEqual(bitmap1, bitmap2); |
| 68 } | 68 } |
| 69 | 69 |
| 70 class BrowserActionApiTest : public ExtensionApiTest { | 70 class BrowserActionApiTest : public ExtensionApiTest { |
| 71 public: | 71 public: |
| 72 BrowserActionApiTest() {} | 72 BrowserActionApiTest() {} |
| 73 ~BrowserActionApiTest() override {} | 73 ~BrowserActionApiTest() override {} |
| 74 | 74 |
| 75 protected: | 75 protected: |
| 76 BrowserActionTestUtil GetBrowserActionsBar() { | 76 BrowserActionTestUtil* GetBrowserActionsBar() { |
| 77 return BrowserActionTestUtil(browser()); | 77 if (!browser_action_test_util_) |
| 78 browser_action_test_util_.reset(new BrowserActionTestUtil(browser())); |
| 79 return browser_action_test_util_.get(); |
| 78 } | 80 } |
| 79 | 81 |
| 80 bool OpenPopup(int index) { | 82 bool OpenPopup(int index) { |
| 81 ResultCatcher catcher; | 83 ResultCatcher catcher; |
| 82 content::WindowedNotificationObserver popup_observer( | 84 content::WindowedNotificationObserver popup_observer( |
| 83 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 85 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 84 content::NotificationService::AllSources()); | 86 content::NotificationService::AllSources()); |
| 85 GetBrowserActionsBar().Press(index); | 87 GetBrowserActionsBar()->Press(index); |
| 86 popup_observer.Wait(); | 88 popup_observer.Wait(); |
| 87 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 89 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 88 return GetBrowserActionsBar().HasPopup(); | 90 return GetBrowserActionsBar()->HasPopup(); |
| 89 } | 91 } |
| 90 | 92 |
| 91 ExtensionAction* GetBrowserAction(const Extension& extension) { | 93 ExtensionAction* GetBrowserAction(const Extension& extension) { |
| 92 return ExtensionActionManager::Get(browser()->profile())-> | 94 return ExtensionActionManager::Get(browser()->profile())-> |
| 93 GetBrowserAction(extension); | 95 GetBrowserAction(extension); |
| 94 } | 96 } |
| 97 |
| 98 private: |
| 99 scoped_ptr<BrowserActionTestUtil> browser_action_test_util_; |
| 100 |
| 101 DISALLOW_COPY_AND_ASSIGN(BrowserActionApiTest); |
| 95 }; | 102 }; |
| 96 | 103 |
| 97 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, Basic) { | 104 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, Basic) { |
| 98 ASSERT_TRUE(test_server()->Start()); | 105 ASSERT_TRUE(test_server()->Start()); |
| 99 ASSERT_TRUE(RunExtensionTest("browser_action/basics")) << message_; | 106 ASSERT_TRUE(RunExtensionTest("browser_action/basics")) << message_; |
| 100 const Extension* extension = GetSingleLoadedExtension(); | 107 const Extension* extension = GetSingleLoadedExtension(); |
| 101 ASSERT_TRUE(extension) << message_; | 108 ASSERT_TRUE(extension) << message_; |
| 102 | 109 |
| 103 // Test that there is a browser action in the toolbar. | 110 // Test that there is a browser action in the toolbar. |
| 104 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions()); | 111 ASSERT_EQ(1, GetBrowserActionsBar()->NumberOfBrowserActions()); |
| 105 | 112 |
| 106 // Tell the extension to update the browser action state. | 113 // Tell the extension to update the browser action state. |
| 107 ResultCatcher catcher; | 114 ResultCatcher catcher; |
| 108 ui_test_utils::NavigateToURL(browser(), | 115 ui_test_utils::NavigateToURL(browser(), |
| 109 GURL(extension->GetResourceURL("update.html"))); | 116 GURL(extension->GetResourceURL("update.html"))); |
| 110 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 117 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 111 | 118 |
| 112 // Test that we received the changes. | 119 // Test that we received the changes. |
| 113 ExtensionAction* action = GetBrowserAction(*extension); | 120 ExtensionAction* action = GetBrowserAction(*extension); |
| 114 ASSERT_EQ("Modified", action->GetTitle(ExtensionAction::kDefaultTabId)); | 121 ASSERT_EQ("Modified", action->GetTitle(ExtensionAction::kDefaultTabId)); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 141 #endif | 148 #endif |
| 142 | 149 |
| 143 // We should not be creating icons asynchronously, so we don't need an | 150 // We should not be creating icons asynchronously, so we don't need an |
| 144 // observer. | 151 // observer. |
| 145 ExtensionActionIconFactory icon_factory( | 152 ExtensionActionIconFactory icon_factory( |
| 146 profile(), | 153 profile(), |
| 147 extension, | 154 extension, |
| 148 GetBrowserAction(*extension), | 155 GetBrowserAction(*extension), |
| 149 NULL); | 156 NULL); |
| 150 // Test that there is a browser action in the toolbar. | 157 // Test that there is a browser action in the toolbar. |
| 151 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions()); | 158 ASSERT_EQ(1, GetBrowserActionsBar()->NumberOfBrowserActions()); |
| 152 EXPECT_TRUE(GetBrowserActionsBar().HasIcon(0)); | 159 EXPECT_TRUE(GetBrowserActionsBar()->HasIcon(0)); |
| 153 | 160 |
| 154 gfx::Image action_icon = icon_factory.GetIcon(0); | 161 gfx::Image action_icon = icon_factory.GetIcon(0); |
| 155 uint32_t action_icon_last_id = action_icon.ToSkBitmap()->getGenerationID(); | 162 uint32_t action_icon_last_id = action_icon.ToSkBitmap()->getGenerationID(); |
| 156 | 163 |
| 157 // Let's check that |GetIcon| doesn't always return bitmap with new id. | 164 // Let's check that |GetIcon| doesn't always return bitmap with new id. |
| 158 ASSERT_EQ(action_icon_last_id, | 165 ASSERT_EQ(action_icon_last_id, |
| 159 icon_factory.GetIcon(0).ToSkBitmap()->getGenerationID()); | 166 icon_factory.GetIcon(0).ToSkBitmap()->getGenerationID()); |
| 160 | 167 |
| 161 uint32_t action_icon_current_id = 0; | 168 uint32_t action_icon_current_id = 0; |
| 162 | 169 |
| 163 ResultCatcher catcher; | 170 ResultCatcher catcher; |
| 164 | 171 |
| 165 // Tell the extension to update the icon using ImageData object. | 172 // Tell the extension to update the icon using ImageData object. |
| 166 GetBrowserActionsBar().Press(0); | 173 GetBrowserActionsBar()->Press(0); |
| 167 ASSERT_TRUE(catcher.GetNextResult()); | 174 ASSERT_TRUE(catcher.GetNextResult()); |
| 168 | 175 |
| 169 action_icon = icon_factory.GetIcon(0); | 176 action_icon = icon_factory.GetIcon(0); |
| 170 | 177 |
| 171 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); | 178 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); |
| 172 EXPECT_GT(action_icon_current_id, action_icon_last_id); | 179 EXPECT_GT(action_icon_current_id, action_icon_last_id); |
| 173 action_icon_last_id = action_icon_current_id; | 180 action_icon_last_id = action_icon_current_id; |
| 174 | 181 |
| 175 EXPECT_FALSE(action_icon.ToImageSkia()->HasRepresentation(2.0f)); | 182 EXPECT_FALSE(action_icon.ToImageSkia()->HasRepresentation(2.0f)); |
| 176 | 183 |
| 177 EXPECT_TRUE( | 184 EXPECT_TRUE( |
| 178 ImagesAreEqualAtScale(AddBackgroundForViews(*action_icon.ToImageSkia()), | 185 ImagesAreEqualAtScale(AddBackgroundForViews(*action_icon.ToImageSkia()), |
| 179 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), | 186 *GetBrowserActionsBar()->GetIcon(0).ToImageSkia(), |
| 180 1.0f)); | 187 1.0f)); |
| 181 | 188 |
| 182 // Tell the extension to update the icon using path. | 189 // Tell the extension to update the icon using path. |
| 183 GetBrowserActionsBar().Press(0); | 190 GetBrowserActionsBar()->Press(0); |
| 184 ASSERT_TRUE(catcher.GetNextResult()); | 191 ASSERT_TRUE(catcher.GetNextResult()); |
| 185 | 192 |
| 186 action_icon = icon_factory.GetIcon(0); | 193 action_icon = icon_factory.GetIcon(0); |
| 187 | 194 |
| 188 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); | 195 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); |
| 189 EXPECT_GT(action_icon_current_id, action_icon_last_id); | 196 EXPECT_GT(action_icon_current_id, action_icon_last_id); |
| 190 action_icon_last_id = action_icon_current_id; | 197 action_icon_last_id = action_icon_current_id; |
| 191 | 198 |
| 192 EXPECT_FALSE( | 199 EXPECT_FALSE( |
| 193 action_icon.ToImageSkia()->HasRepresentation(2.0f)); | 200 action_icon.ToImageSkia()->HasRepresentation(2.0f)); |
| 194 | 201 |
| 195 EXPECT_TRUE( | 202 EXPECT_TRUE( |
| 196 ImagesAreEqualAtScale(AddBackgroundForViews(*action_icon.ToImageSkia()), | 203 ImagesAreEqualAtScale(AddBackgroundForViews(*action_icon.ToImageSkia()), |
| 197 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), | 204 *GetBrowserActionsBar()->GetIcon(0).ToImageSkia(), |
| 198 1.0f)); | 205 1.0f)); |
| 199 | 206 |
| 200 // Tell the extension to update the icon using dictionary of ImageData | 207 // Tell the extension to update the icon using dictionary of ImageData |
| 201 // objects. | 208 // objects. |
| 202 GetBrowserActionsBar().Press(0); | 209 GetBrowserActionsBar()->Press(0); |
| 203 ASSERT_TRUE(catcher.GetNextResult()); | 210 ASSERT_TRUE(catcher.GetNextResult()); |
| 204 | 211 |
| 205 action_icon = icon_factory.GetIcon(0); | 212 action_icon = icon_factory.GetIcon(0); |
| 206 | 213 |
| 207 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); | 214 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); |
| 208 EXPECT_GT(action_icon_current_id, action_icon_last_id); | 215 EXPECT_GT(action_icon_current_id, action_icon_last_id); |
| 209 action_icon_last_id = action_icon_current_id; | 216 action_icon_last_id = action_icon_current_id; |
| 210 | 217 |
| 211 EXPECT_TRUE(action_icon.ToImageSkia()->HasRepresentation(2.0f)); | 218 EXPECT_TRUE(action_icon.ToImageSkia()->HasRepresentation(2.0f)); |
| 212 | 219 |
| 213 EXPECT_TRUE( | 220 EXPECT_TRUE( |
| 214 ImagesAreEqualAtScale(AddBackgroundForViews(*action_icon.ToImageSkia()), | 221 ImagesAreEqualAtScale(AddBackgroundForViews(*action_icon.ToImageSkia()), |
| 215 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), | 222 *GetBrowserActionsBar()->GetIcon(0).ToImageSkia(), |
| 216 1.0f)); | 223 1.0f)); |
| 217 | 224 |
| 218 // Tell the extension to update the icon using dictionary of paths. | 225 // Tell the extension to update the icon using dictionary of paths. |
| 219 GetBrowserActionsBar().Press(0); | 226 GetBrowserActionsBar()->Press(0); |
| 220 ASSERT_TRUE(catcher.GetNextResult()); | 227 ASSERT_TRUE(catcher.GetNextResult()); |
| 221 | 228 |
| 222 action_icon = icon_factory.GetIcon(0); | 229 action_icon = icon_factory.GetIcon(0); |
| 223 | 230 |
| 224 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); | 231 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); |
| 225 EXPECT_GT(action_icon_current_id, action_icon_last_id); | 232 EXPECT_GT(action_icon_current_id, action_icon_last_id); |
| 226 action_icon_last_id = action_icon_current_id; | 233 action_icon_last_id = action_icon_current_id; |
| 227 | 234 |
| 228 EXPECT_TRUE(action_icon.ToImageSkia()->HasRepresentation(2.0f)); | 235 EXPECT_TRUE(action_icon.ToImageSkia()->HasRepresentation(2.0f)); |
| 229 | 236 |
| 230 EXPECT_TRUE( | 237 EXPECT_TRUE( |
| 231 ImagesAreEqualAtScale(AddBackgroundForViews(*action_icon.ToImageSkia()), | 238 ImagesAreEqualAtScale(AddBackgroundForViews(*action_icon.ToImageSkia()), |
| 232 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), | 239 *GetBrowserActionsBar()->GetIcon(0).ToImageSkia(), |
| 233 1.0f)); | 240 1.0f)); |
| 234 | 241 |
| 235 // Tell the extension to update the icon using dictionary of ImageData | 242 // Tell the extension to update the icon using dictionary of ImageData |
| 236 // objects, but setting only size 19. | 243 // objects, but setting only size 19. |
| 237 GetBrowserActionsBar().Press(0); | 244 GetBrowserActionsBar()->Press(0); |
| 238 ASSERT_TRUE(catcher.GetNextResult()); | 245 ASSERT_TRUE(catcher.GetNextResult()); |
| 239 | 246 |
| 240 action_icon = icon_factory.GetIcon(0); | 247 action_icon = icon_factory.GetIcon(0); |
| 241 | 248 |
| 242 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); | 249 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); |
| 243 EXPECT_GT(action_icon_current_id, action_icon_last_id); | 250 EXPECT_GT(action_icon_current_id, action_icon_last_id); |
| 244 action_icon_last_id = action_icon_current_id; | 251 action_icon_last_id = action_icon_current_id; |
| 245 | 252 |
| 246 EXPECT_FALSE(action_icon.ToImageSkia()->HasRepresentation(2.0f)); | 253 EXPECT_FALSE(action_icon.ToImageSkia()->HasRepresentation(2.0f)); |
| 247 | 254 |
| 248 EXPECT_TRUE( | 255 EXPECT_TRUE( |
| 249 ImagesAreEqualAtScale(AddBackgroundForViews(*action_icon.ToImageSkia()), | 256 ImagesAreEqualAtScale(AddBackgroundForViews(*action_icon.ToImageSkia()), |
| 250 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), | 257 *GetBrowserActionsBar()->GetIcon(0).ToImageSkia(), |
| 251 1.0f)); | 258 1.0f)); |
| 252 | 259 |
| 253 // Tell the extension to update the icon using dictionary of paths, but | 260 // Tell the extension to update the icon using dictionary of paths, but |
| 254 // setting only size 19. | 261 // setting only size 19. |
| 255 GetBrowserActionsBar().Press(0); | 262 GetBrowserActionsBar()->Press(0); |
| 256 ASSERT_TRUE(catcher.GetNextResult()); | 263 ASSERT_TRUE(catcher.GetNextResult()); |
| 257 | 264 |
| 258 action_icon = icon_factory.GetIcon(0); | 265 action_icon = icon_factory.GetIcon(0); |
| 259 | 266 |
| 260 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); | 267 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); |
| 261 EXPECT_GT(action_icon_current_id, action_icon_last_id); | 268 EXPECT_GT(action_icon_current_id, action_icon_last_id); |
| 262 action_icon_last_id = action_icon_current_id; | 269 action_icon_last_id = action_icon_current_id; |
| 263 | 270 |
| 264 EXPECT_FALSE(action_icon.ToImageSkia()->HasRepresentation(2.0f)); | 271 EXPECT_FALSE(action_icon.ToImageSkia()->HasRepresentation(2.0f)); |
| 265 | 272 |
| 266 EXPECT_TRUE( | 273 EXPECT_TRUE( |
| 267 ImagesAreEqualAtScale(AddBackgroundForViews(*action_icon.ToImageSkia()), | 274 ImagesAreEqualAtScale(AddBackgroundForViews(*action_icon.ToImageSkia()), |
| 268 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), | 275 *GetBrowserActionsBar()->GetIcon(0).ToImageSkia(), |
| 269 1.0f)); | 276 1.0f)); |
| 270 | 277 |
| 271 // Tell the extension to update the icon using dictionary of ImageData | 278 // Tell the extension to update the icon using dictionary of ImageData |
| 272 // objects, but setting only size 38. | 279 // objects, but setting only size 38. |
| 273 GetBrowserActionsBar().Press(0); | 280 GetBrowserActionsBar()->Press(0); |
| 274 ASSERT_TRUE(catcher.GetNextResult()); | 281 ASSERT_TRUE(catcher.GetNextResult()); |
| 275 | 282 |
| 276 action_icon = icon_factory.GetIcon(0); | 283 action_icon = icon_factory.GetIcon(0); |
| 277 | 284 |
| 278 const gfx::ImageSkia* action_icon_skia = action_icon.ToImageSkia(); | 285 const gfx::ImageSkia* action_icon_skia = action_icon.ToImageSkia(); |
| 279 | 286 |
| 280 EXPECT_FALSE(action_icon_skia->HasRepresentation(1.0f)); | 287 EXPECT_FALSE(action_icon_skia->HasRepresentation(1.0f)); |
| 281 EXPECT_TRUE(action_icon_skia->HasRepresentation(2.0f)); | 288 EXPECT_TRUE(action_icon_skia->HasRepresentation(2.0f)); |
| 282 | 289 |
| 283 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); | 290 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); |
| 284 EXPECT_GT(action_icon_current_id, action_icon_last_id); | 291 EXPECT_GT(action_icon_current_id, action_icon_last_id); |
| 285 action_icon_last_id = action_icon_current_id; | 292 action_icon_last_id = action_icon_current_id; |
| 286 | 293 |
| 287 EXPECT_TRUE(gfx::BitmapsAreEqual( | 294 EXPECT_TRUE(gfx::BitmapsAreEqual( |
| 288 *action_icon.ToSkBitmap(), | 295 *action_icon.ToSkBitmap(), |
| 289 action_icon_skia->GetRepresentation(2.0f).sk_bitmap())); | 296 action_icon_skia->GetRepresentation(2.0f).sk_bitmap())); |
| 290 | 297 |
| 291 EXPECT_TRUE( | 298 EXPECT_TRUE( |
| 292 ImagesAreEqualAtScale(AddBackgroundForViews(*action_icon_skia), | 299 ImagesAreEqualAtScale(AddBackgroundForViews(*action_icon_skia), |
| 293 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), | 300 *GetBrowserActionsBar()->GetIcon(0).ToImageSkia(), |
| 294 2.0f)); | 301 2.0f)); |
| 295 | 302 |
| 296 // Try setting icon with empty dictionary of ImageData objects. | 303 // Try setting icon with empty dictionary of ImageData objects. |
| 297 GetBrowserActionsBar().Press(0); | 304 GetBrowserActionsBar()->Press(0); |
| 298 ASSERT_FALSE(catcher.GetNextResult()); | 305 ASSERT_FALSE(catcher.GetNextResult()); |
| 299 EXPECT_EQ(kEmptyImageDataError, catcher.message()); | 306 EXPECT_EQ(kEmptyImageDataError, catcher.message()); |
| 300 | 307 |
| 301 // Try setting icon with empty dictionary of path objects. | 308 // Try setting icon with empty dictionary of path objects. |
| 302 GetBrowserActionsBar().Press(0); | 309 GetBrowserActionsBar()->Press(0); |
| 303 ASSERT_FALSE(catcher.GetNextResult()); | 310 ASSERT_FALSE(catcher.GetNextResult()); |
| 304 EXPECT_EQ(kEmptyPathError, catcher.message()); | 311 EXPECT_EQ(kEmptyPathError, catcher.message()); |
| 305 } | 312 } |
| 306 | 313 |
| 307 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, TabSpecificBrowserActionState) { | 314 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, TabSpecificBrowserActionState) { |
| 308 ASSERT_TRUE(RunExtensionTest("browser_action/tab_specific_state")) << | 315 ASSERT_TRUE(RunExtensionTest("browser_action/tab_specific_state")) << |
| 309 message_; | 316 message_; |
| 310 const Extension* extension = GetSingleLoadedExtension(); | 317 const Extension* extension = GetSingleLoadedExtension(); |
| 311 ASSERT_TRUE(extension) << message_; | 318 ASSERT_TRUE(extension) << message_; |
| 312 | 319 |
| 313 // Test that there is a browser action in the toolbar and that it has an icon. | 320 // Test that there is a browser action in the toolbar and that it has an icon. |
| 314 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions()); | 321 ASSERT_EQ(1, GetBrowserActionsBar()->NumberOfBrowserActions()); |
| 315 EXPECT_TRUE(GetBrowserActionsBar().HasIcon(0)); | 322 EXPECT_TRUE(GetBrowserActionsBar()->HasIcon(0)); |
| 316 | 323 |
| 317 // Execute the action, its title should change. | 324 // Execute the action, its title should change. |
| 318 ResultCatcher catcher; | 325 ResultCatcher catcher; |
| 319 GetBrowserActionsBar().Press(0); | 326 GetBrowserActionsBar()->Press(0); |
| 320 ASSERT_TRUE(catcher.GetNextResult()); | 327 ASSERT_TRUE(catcher.GetNextResult()); |
| 321 EXPECT_EQ("Showing icon 2", GetBrowserActionsBar().GetTooltip(0)); | 328 EXPECT_EQ("Showing icon 2", GetBrowserActionsBar()->GetTooltip(0)); |
| 322 | 329 |
| 323 // Open a new tab, the title should go back. | 330 // Open a new tab, the title should go back. |
| 324 chrome::NewTab(browser()); | 331 chrome::NewTab(browser()); |
| 325 EXPECT_EQ("hi!", GetBrowserActionsBar().GetTooltip(0)); | 332 EXPECT_EQ("hi!", GetBrowserActionsBar()->GetTooltip(0)); |
| 326 | 333 |
| 327 // Go back to first tab, changed title should reappear. | 334 // Go back to first tab, changed title should reappear. |
| 328 browser()->tab_strip_model()->ActivateTabAt(0, true); | 335 browser()->tab_strip_model()->ActivateTabAt(0, true); |
| 329 EXPECT_EQ("Showing icon 2", GetBrowserActionsBar().GetTooltip(0)); | 336 EXPECT_EQ("Showing icon 2", GetBrowserActionsBar()->GetTooltip(0)); |
| 330 | 337 |
| 331 // Reload that tab, default title should come back. | 338 // Reload that tab, default title should come back. |
| 332 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); | 339 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
| 333 EXPECT_EQ("hi!", GetBrowserActionsBar().GetTooltip(0)); | 340 EXPECT_EQ("hi!", GetBrowserActionsBar()->GetTooltip(0)); |
| 334 } | 341 } |
| 335 | 342 |
| 336 // http://code.google.com/p/chromium/issues/detail?id=70829 | 343 // http://code.google.com/p/chromium/issues/detail?id=70829 |
| 337 // Mac used to be ok, but then mac 10.5 started failing too. =( | 344 // Mac used to be ok, but then mac 10.5 started failing too. =( |
| 338 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DISABLED_BrowserActionPopup) { | 345 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DISABLED_BrowserActionPopup) { |
| 339 ASSERT_TRUE( | 346 ASSERT_TRUE( |
| 340 LoadExtension(test_data_dir_.AppendASCII("browser_action/popup"))); | 347 LoadExtension(test_data_dir_.AppendASCII("browser_action/popup"))); |
| 341 BrowserActionTestUtil actions_bar = GetBrowserActionsBar(); | 348 BrowserActionTestUtil* actions_bar = GetBrowserActionsBar(); |
| 342 const Extension* extension = GetSingleLoadedExtension(); | 349 const Extension* extension = GetSingleLoadedExtension(); |
| 343 ASSERT_TRUE(extension) << message_; | 350 ASSERT_TRUE(extension) << message_; |
| 344 | 351 |
| 345 // The extension's popup's size grows by |growFactor| each click. | 352 // The extension's popup's size grows by |growFactor| each click. |
| 346 const int growFactor = 500; | 353 const int growFactor = 500; |
| 347 gfx::Size minSize = BrowserActionTestUtil::GetMinPopupSize(); | 354 gfx::Size minSize = BrowserActionTestUtil::GetMinPopupSize(); |
| 348 gfx::Size middleSize = gfx::Size(growFactor, growFactor); | 355 gfx::Size middleSize = gfx::Size(growFactor, growFactor); |
| 349 gfx::Size maxSize = BrowserActionTestUtil::GetMaxPopupSize(); | 356 gfx::Size maxSize = BrowserActionTestUtil::GetMaxPopupSize(); |
| 350 | 357 |
| 351 // Ensure that two clicks will exceed the maximum allowed size. | 358 // Ensure that two clicks will exceed the maximum allowed size. |
| 352 ASSERT_GT(minSize.height() + growFactor * 2, maxSize.height()); | 359 ASSERT_GT(minSize.height() + growFactor * 2, maxSize.height()); |
| 353 ASSERT_GT(minSize.width() + growFactor * 2, maxSize.width()); | 360 ASSERT_GT(minSize.width() + growFactor * 2, maxSize.width()); |
| 354 | 361 |
| 355 // Simulate a click on the browser action and verify the size of the resulting | 362 // Simulate a click on the browser action and verify the size of the resulting |
| 356 // popup. The first one tries to be 0x0, so it should be the min values. | 363 // popup. The first one tries to be 0x0, so it should be the min values. |
| 357 ASSERT_TRUE(OpenPopup(0)); | 364 ASSERT_TRUE(OpenPopup(0)); |
| 358 EXPECT_EQ(minSize, actions_bar.GetPopupSize()); | 365 EXPECT_EQ(minSize, actions_bar->GetPopupSize()); |
| 359 EXPECT_TRUE(actions_bar.HidePopup()); | 366 EXPECT_TRUE(actions_bar->HidePopup()); |
| 360 | 367 |
| 361 ASSERT_TRUE(OpenPopup(0)); | 368 ASSERT_TRUE(OpenPopup(0)); |
| 362 EXPECT_EQ(middleSize, actions_bar.GetPopupSize()); | 369 EXPECT_EQ(middleSize, actions_bar->GetPopupSize()); |
| 363 EXPECT_TRUE(actions_bar.HidePopup()); | 370 EXPECT_TRUE(actions_bar->HidePopup()); |
| 364 | 371 |
| 365 // One more time, but this time it should be constrained by the max values. | 372 // One more time, but this time it should be constrained by the max values. |
| 366 ASSERT_TRUE(OpenPopup(0)); | 373 ASSERT_TRUE(OpenPopup(0)); |
| 367 EXPECT_EQ(maxSize, actions_bar.GetPopupSize()); | 374 EXPECT_EQ(maxSize, actions_bar->GetPopupSize()); |
| 368 EXPECT_TRUE(actions_bar.HidePopup()); | 375 EXPECT_TRUE(actions_bar->HidePopup()); |
| 369 } | 376 } |
| 370 | 377 |
| 371 // Test that calling chrome.browserAction.setPopup() can enable and change | 378 // Test that calling chrome.browserAction.setPopup() can enable and change |
| 372 // a popup. | 379 // a popup. |
| 373 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BrowserActionAddPopup) { | 380 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BrowserActionAddPopup) { |
| 374 ASSERT_TRUE(RunExtensionTest("browser_action/add_popup")) << message_; | 381 ASSERT_TRUE(RunExtensionTest("browser_action/add_popup")) << message_; |
| 375 const Extension* extension = GetSingleLoadedExtension(); | 382 const Extension* extension = GetSingleLoadedExtension(); |
| 376 ASSERT_TRUE(extension) << message_; | 383 ASSERT_TRUE(extension) << message_; |
| 377 | 384 |
| 378 int tab_id = ExtensionTabUtil::GetTabId( | 385 int tab_id = ExtensionTabUtil::GetTabId( |
| 379 browser()->tab_strip_model()->GetActiveWebContents()); | 386 browser()->tab_strip_model()->GetActiveWebContents()); |
| 380 | 387 |
| 381 ExtensionAction* browser_action = GetBrowserAction(*extension); | 388 ExtensionAction* browser_action = GetBrowserAction(*extension); |
| 382 ASSERT_TRUE(browser_action) | 389 ASSERT_TRUE(browser_action) |
| 383 << "Browser action test extension should have a browser action."; | 390 << "Browser action test extension should have a browser action."; |
| 384 | 391 |
| 385 ASSERT_FALSE(browser_action->HasPopup(tab_id)); | 392 ASSERT_FALSE(browser_action->HasPopup(tab_id)); |
| 386 ASSERT_FALSE(browser_action->HasPopup(ExtensionAction::kDefaultTabId)); | 393 ASSERT_FALSE(browser_action->HasPopup(ExtensionAction::kDefaultTabId)); |
| 387 | 394 |
| 388 // Simulate a click on the browser action icon. The onClicked handler | 395 // Simulate a click on the browser action icon. The onClicked handler |
| 389 // will add a popup. | 396 // will add a popup. |
| 390 { | 397 { |
| 391 ResultCatcher catcher; | 398 ResultCatcher catcher; |
| 392 GetBrowserActionsBar().Press(0); | 399 GetBrowserActionsBar()->Press(0); |
| 393 ASSERT_TRUE(catcher.GetNextResult()); | 400 ASSERT_TRUE(catcher.GetNextResult()); |
| 394 } | 401 } |
| 395 | 402 |
| 396 // The call to setPopup in background.html set a tab id, so the | 403 // The call to setPopup in background.html set a tab id, so the |
| 397 // current tab's setting should have changed, but the default setting | 404 // current tab's setting should have changed, but the default setting |
| 398 // should not have changed. | 405 // should not have changed. |
| 399 ASSERT_TRUE(browser_action->HasPopup(tab_id)) | 406 ASSERT_TRUE(browser_action->HasPopup(tab_id)) |
| 400 << "Clicking on the browser action should have caused a popup to " | 407 << "Clicking on the browser action should have caused a popup to " |
| 401 << "be added."; | 408 << "be added."; |
| 402 ASSERT_FALSE(browser_action->HasPopup(ExtensionAction::kDefaultTabId)) | 409 ASSERT_FALSE(browser_action->HasPopup(ExtensionAction::kDefaultTabId)) |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 } | 467 } |
| 461 | 468 |
| 462 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, IncognitoBasic) { | 469 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, IncognitoBasic) { |
| 463 ASSERT_TRUE(test_server()->Start()); | 470 ASSERT_TRUE(test_server()->Start()); |
| 464 | 471 |
| 465 ASSERT_TRUE(RunExtensionTest("browser_action/basics")) << message_; | 472 ASSERT_TRUE(RunExtensionTest("browser_action/basics")) << message_; |
| 466 const Extension* extension = GetSingleLoadedExtension(); | 473 const Extension* extension = GetSingleLoadedExtension(); |
| 467 ASSERT_TRUE(extension) << message_; | 474 ASSERT_TRUE(extension) << message_; |
| 468 | 475 |
| 469 // Test that there is a browser action in the toolbar. | 476 // Test that there is a browser action in the toolbar. |
| 470 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions()); | 477 ASSERT_EQ(1, GetBrowserActionsBar()->NumberOfBrowserActions()); |
| 471 | 478 |
| 472 // Open an incognito window and test that the browser action isn't there by | 479 // Open an incognito window and test that the browser action isn't there by |
| 473 // default. | 480 // default. |
| 474 Profile* incognito_profile = browser()->profile()->GetOffTheRecordProfile(); | 481 Profile* incognito_profile = browser()->profile()->GetOffTheRecordProfile(); |
| 475 base::RunLoop().RunUntilIdle(); // Wait for profile initialization. | 482 base::RunLoop().RunUntilIdle(); // Wait for profile initialization. |
| 476 Browser* incognito_browser = | 483 Browser* incognito_browser = |
| 477 new Browser(Browser::CreateParams(incognito_profile, | 484 new Browser(Browser::CreateParams(incognito_profile, |
| 478 browser()->host_desktop_type())); | 485 browser()->host_desktop_type())); |
| 479 | 486 |
| 480 ASSERT_EQ(0, | 487 ASSERT_EQ(0, |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 ASSERT_EQ("X", action->GetBadgeText(ExtensionAction::kDefaultTabId)); | 568 ASSERT_EQ("X", action->GetBadgeText(ExtensionAction::kDefaultTabId)); |
| 562 } | 569 } |
| 563 | 570 |
| 564 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BadgeBackgroundColor) { | 571 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BadgeBackgroundColor) { |
| 565 ASSERT_TRUE(test_server()->Start()); | 572 ASSERT_TRUE(test_server()->Start()); |
| 566 ASSERT_TRUE(RunExtensionTest("browser_action/color")) << message_; | 573 ASSERT_TRUE(RunExtensionTest("browser_action/color")) << message_; |
| 567 const Extension* extension = GetSingleLoadedExtension(); | 574 const Extension* extension = GetSingleLoadedExtension(); |
| 568 ASSERT_TRUE(extension) << message_; | 575 ASSERT_TRUE(extension) << message_; |
| 569 | 576 |
| 570 // Test that there is a browser action in the toolbar. | 577 // Test that there is a browser action in the toolbar. |
| 571 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions()); | 578 ASSERT_EQ(1, GetBrowserActionsBar()->NumberOfBrowserActions()); |
| 572 | 579 |
| 573 // Test that CSS values (#FF0000) set color correctly. | 580 // Test that CSS values (#FF0000) set color correctly. |
| 574 ExtensionAction* action = GetBrowserAction(*extension); | 581 ExtensionAction* action = GetBrowserAction(*extension); |
| 575 ASSERT_EQ(SkColorSetARGB(255, 255, 0, 0), | 582 ASSERT_EQ(SkColorSetARGB(255, 255, 0, 0), |
| 576 action->GetBadgeBackgroundColor(ExtensionAction::kDefaultTabId)); | 583 action->GetBadgeBackgroundColor(ExtensionAction::kDefaultTabId)); |
| 577 | 584 |
| 578 // Tell the extension to update the browser action state. | 585 // Tell the extension to update the browser action state. |
| 579 ResultCatcher catcher; | 586 ResultCatcher catcher; |
| 580 ui_test_utils::NavigateToURL(browser(), | 587 ui_test_utils::NavigateToURL(browser(), |
| 581 GURL(extension->GetResourceURL("update.html"))); | 588 GURL(extension->GetResourceURL("update.html"))); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 593 ASSERT_EQ(SkColorSetARGB(255, 255, 255, 255), | 600 ASSERT_EQ(SkColorSetARGB(255, 255, 255, 255), |
| 594 action->GetBadgeBackgroundColor(ExtensionAction::kDefaultTabId)); | 601 action->GetBadgeBackgroundColor(ExtensionAction::kDefaultTabId)); |
| 595 } | 602 } |
| 596 | 603 |
| 597 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, Getters) { | 604 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, Getters) { |
| 598 ASSERT_TRUE(RunExtensionTest("browser_action/getters")) << message_; | 605 ASSERT_TRUE(RunExtensionTest("browser_action/getters")) << message_; |
| 599 const Extension* extension = GetSingleLoadedExtension(); | 606 const Extension* extension = GetSingleLoadedExtension(); |
| 600 ASSERT_TRUE(extension) << message_; | 607 ASSERT_TRUE(extension) << message_; |
| 601 | 608 |
| 602 // Test that there is a browser action in the toolbar. | 609 // Test that there is a browser action in the toolbar. |
| 603 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions()); | 610 ASSERT_EQ(1, GetBrowserActionsBar()->NumberOfBrowserActions()); |
| 604 | 611 |
| 605 // Test the getters for defaults. | 612 // Test the getters for defaults. |
| 606 ResultCatcher catcher; | 613 ResultCatcher catcher; |
| 607 ui_test_utils::NavigateToURL(browser(), | 614 ui_test_utils::NavigateToURL(browser(), |
| 608 GURL(extension->GetResourceURL("update.html"))); | 615 GURL(extension->GetResourceURL("update.html"))); |
| 609 ASSERT_TRUE(catcher.GetNextResult()); | 616 ASSERT_TRUE(catcher.GetNextResult()); |
| 610 | 617 |
| 611 // Test the getters for a specific tab. | 618 // Test the getters for a specific tab. |
| 612 ui_test_utils::NavigateToURL(browser(), | 619 ui_test_utils::NavigateToURL(browser(), |
| 613 GURL(extension->GetResourceURL("update2.html"))); | 620 GURL(extension->GetResourceURL("update2.html"))); |
| 614 ASSERT_TRUE(catcher.GetNextResult()); | 621 ASSERT_TRUE(catcher.GetNextResult()); |
| 615 } | 622 } |
| 616 | 623 |
| 617 // Verify triggering browser action. | 624 // Verify triggering browser action. |
| 618 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, TestTriggerBrowserAction) { | 625 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, TestTriggerBrowserAction) { |
| 619 ASSERT_TRUE(test_server()->Start()); | 626 ASSERT_TRUE(test_server()->Start()); |
| 620 | 627 |
| 621 ASSERT_TRUE(RunExtensionTest("trigger_actions/browser_action")) << message_; | 628 ASSERT_TRUE(RunExtensionTest("trigger_actions/browser_action")) << message_; |
| 622 const Extension* extension = GetSingleLoadedExtension(); | 629 const Extension* extension = GetSingleLoadedExtension(); |
| 623 ASSERT_TRUE(extension) << message_; | 630 ASSERT_TRUE(extension) << message_; |
| 624 | 631 |
| 625 // Test that there is a browser action in the toolbar. | 632 // Test that there is a browser action in the toolbar. |
| 626 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions()); | 633 ASSERT_EQ(1, GetBrowserActionsBar()->NumberOfBrowserActions()); |
| 627 | 634 |
| 628 ui_test_utils::NavigateToURL( | 635 ui_test_utils::NavigateToURL( |
| 629 browser(), | 636 browser(), |
| 630 test_server()->GetURL("files/simple.html")); | 637 test_server()->GetURL("files/simple.html")); |
| 631 | 638 |
| 632 ExtensionAction* browser_action = GetBrowserAction(*extension); | 639 ExtensionAction* browser_action = GetBrowserAction(*extension); |
| 633 EXPECT_TRUE(browser_action != NULL); | 640 EXPECT_TRUE(browser_action != NULL); |
| 634 | 641 |
| 635 // Simulate a click on the browser action icon. | 642 // Simulate a click on the browser action icon. |
| 636 { | 643 { |
| 637 ResultCatcher catcher; | 644 ResultCatcher catcher; |
| 638 GetBrowserActionsBar().Press(0); | 645 GetBrowserActionsBar()->Press(0); |
| 639 EXPECT_TRUE(catcher.GetNextResult()); | 646 EXPECT_TRUE(catcher.GetNextResult()); |
| 640 } | 647 } |
| 641 | 648 |
| 642 WebContents* tab = | 649 WebContents* tab = |
| 643 browser()->tab_strip_model()->GetActiveWebContents(); | 650 browser()->tab_strip_model()->GetActiveWebContents(); |
| 644 EXPECT_TRUE(tab != NULL); | 651 EXPECT_TRUE(tab != NULL); |
| 645 | 652 |
| 646 // Verify that the browser action turned the background color red. | 653 // Verify that the browser action turned the background color red. |
| 647 const std::string script = | 654 const std::string script = |
| 648 "window.domAutomationController.send(document.body.style." | 655 "window.domAutomationController.send(document.body.style." |
| 649 "backgroundColor);"; | 656 "backgroundColor);"; |
| 650 std::string result; | 657 std::string result; |
| 651 EXPECT_TRUE(content::ExecuteScriptAndExtractString(tab, script, &result)); | 658 EXPECT_TRUE(content::ExecuteScriptAndExtractString(tab, script, &result)); |
| 652 EXPECT_EQ(result, "red"); | 659 EXPECT_EQ(result, "red"); |
| 653 } | 660 } |
| 654 | 661 |
| 655 } // namespace | 662 } // namespace |
| 656 } // namespace extensions | 663 } // namespace extensions |
| OLD | NEW |