OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/i18n/time_formatting.h" |
6 #include "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
7 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
8 #include "chrome/browser/ui/browser_window.h" | 9 #include "chrome/browser/ui/browser_window.h" |
| 10 #include "chrome/browser/ui/panels/about_panel_bubble.h" |
9 #include "chrome/browser/ui/panels/panel.h" | 11 #include "chrome/browser/ui/panels/panel.h" |
10 #include "chrome/browser/ui/panels/panel_browser_frame_view.h" | 12 #include "chrome/browser/ui/panels/panel_browser_frame_view.h" |
11 #include "chrome/browser/ui/panels/panel_browser_view.h" | 13 #include "chrome/browser/ui/panels/panel_browser_view.h" |
| 14 #include "chrome/browser/ui/panels/panel_originator_delegate.h" |
12 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
13 #include "chrome/test/in_process_browser_test.h" | 16 #include "chrome/test/in_process_browser_test.h" |
| 17 #include "grit/generated_resources.h" |
| 18 #include "ui/base/l10n/l10n_util.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "views/controls/button/image_button.h" | 20 #include "views/controls/button/image_button.h" |
16 #include "views/controls/button/menu_button.h" | 21 #include "views/controls/button/menu_button.h" |
| 22 #include "views/controls/image_view.h" |
17 #include "views/controls/label.h" | 23 #include "views/controls/label.h" |
| 24 #include "views/controls/link.h" |
| 25 #include "views/controls/textfield/textfield.h" |
18 #include "views/controls/menu/menu_2.h" | 26 #include "views/controls/menu/menu_2.h" |
19 | 27 |
| 28 class MockPanelOriginator : public PanelOriginatorDelegate { |
| 29 public: |
| 30 MockPanelOriginator() : install_time_(base::Time::Now()) {} |
| 31 virtual ~MockPanelOriginator() {} |
| 32 |
| 33 virtual std::string GetOriginatorName() const OVERRIDE { |
| 34 return "Foo"; |
| 35 } |
| 36 |
| 37 virtual std::string GetOriginatorDescription() const OVERRIDE { |
| 38 return "This is a description."; |
| 39 } |
| 40 |
| 41 virtual base::Time GetOriginatorInstallTime() const OVERRIDE { |
| 42 return install_time_; |
| 43 } |
| 44 |
| 45 private: |
| 46 base::Time install_time_; |
| 47 |
| 48 DISALLOW_COPY_AND_ASSIGN(MockPanelOriginator); |
| 49 }; |
20 | 50 |
21 class PanelBrowserViewTest : public InProcessBrowserTest { | 51 class PanelBrowserViewTest : public InProcessBrowserTest { |
22 public: | 52 public: |
23 PanelBrowserViewTest() : InProcessBrowserTest() { } | 53 PanelBrowserViewTest() : InProcessBrowserTest() { } |
24 | 54 |
25 virtual void SetUpCommandLine(CommandLine* command_line) { | 55 virtual void SetUpCommandLine(CommandLine* command_line) { |
26 command_line->AppendSwitch(switches::kEnablePanels); | 56 command_line->AppendSwitch(switches::kEnablePanels); |
27 } | 57 } |
28 | 58 |
29 protected: | 59 protected: |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 | 271 |
242 // Tests that no dragging is involved. | 272 // Tests that no dragging is involved. |
243 ValidateDragging(browser_view1, 0, 0, 0); | 273 ValidateDragging(browser_view1, 0, 0, 0); |
244 | 274 |
245 browser_view1->Close(); | 275 browser_view1->Close(); |
246 EXPECT_FALSE(browser_view1->panel()); | 276 EXPECT_FALSE(browser_view1->panel()); |
247 | 277 |
248 browser_view2->Close(); | 278 browser_view2->Close(); |
249 EXPECT_FALSE(browser_view2->panel()); | 279 EXPECT_FALSE(browser_view2->panel()); |
250 } | 280 } |
| 281 |
| 282 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, AboutPanelBubble) { |
| 283 PanelBrowserView* browser_view = CreatePanelBrowserView("PanelTest"); |
| 284 scoped_ptr<MockPanelOriginator> mock_originator(new MockPanelOriginator()); |
| 285 |
| 286 AboutPanelBubble* bubble = AboutPanelBubble::Show( |
| 287 browser_view->GetWidget(), |
| 288 gfx::Rect(), |
| 289 BubbleBorder::BOTTOM_RIGHT, |
| 290 SkBitmap(), |
| 291 mock_originator.get()); |
| 292 AboutPanelBubble::AboutPanelBubbleView* contents = |
| 293 static_cast<AboutPanelBubble::AboutPanelBubbleView*>(bubble->contents()); |
| 294 EXPECT_EQ(6, contents->child_count()); |
| 295 EXPECT_TRUE(contents->Contains(contents->icon_)); |
| 296 EXPECT_TRUE(contents->Contains(contents->title_)); |
| 297 EXPECT_TRUE(contents->Contains(contents->install_date_)); |
| 298 EXPECT_TRUE(contents->Contains(contents->description_)); |
| 299 EXPECT_TRUE(contents->Contains(contents->uninstall_link_)); |
| 300 EXPECT_TRUE(contents->Contains(contents->report_abuse_link_)); |
| 301 |
| 302 EXPECT_GT(contents->title_->x(), contents->icon_->x()); |
| 303 EXPECT_GT(contents->title_->width(), 0); |
| 304 EXPECT_GT(contents->title_->height(), 0); |
| 305 EXPECT_EQ(contents->install_date_->x(), contents->title_->x()); |
| 306 EXPECT_GT(contents->install_date_->y(), contents->title_->y()); |
| 307 EXPECT_GT(contents->install_date_->width(), 0); |
| 308 EXPECT_GT(contents->install_date_->height(), 0); |
| 309 EXPECT_EQ(contents->description_->x(), contents->install_date_->x()); |
| 310 EXPECT_GT(contents->description_->y(), contents->install_date_->y()); |
| 311 EXPECT_GT(contents->description_->width(), 0); |
| 312 EXPECT_GT(contents->description_->height(), 0); |
| 313 EXPECT_EQ(contents->uninstall_link_->x(), contents->description_->x()); |
| 314 EXPECT_GT(contents->uninstall_link_->y(), contents->description_->y()); |
| 315 EXPECT_GT(contents->uninstall_link_->width(), 0); |
| 316 EXPECT_GT(contents->uninstall_link_->height(), 0); |
| 317 EXPECT_GT(contents->report_abuse_link_->x(), contents->uninstall_link_->x()); |
| 318 EXPECT_EQ(contents->report_abuse_link_->y(), contents->uninstall_link_->y()); |
| 319 EXPECT_GT(contents->report_abuse_link_->width(), 0); |
| 320 EXPECT_GT(contents->report_abuse_link_->height(), 0); |
| 321 |
| 322 EXPECT_STREQ(mock_originator->GetOriginatorName().c_str(), |
| 323 WideToUTF8(contents->title_->GetText()).c_str()); |
| 324 string16 time_text = l10n_util::GetStringFUTF16( |
| 325 IDS_ABOUT_PANEL_BUBBLE_EXTENSION_INSTALL_DATE, |
| 326 base::TimeFormatFriendlyDate( |
| 327 mock_originator->GetOriginatorInstallTime())); |
| 328 EXPECT_STREQ(UTF16ToUTF8(time_text).c_str(), |
| 329 WideToUTF8(contents->install_date_->GetText()).c_str()); |
| 330 EXPECT_STREQ(mock_originator->GetOriginatorDescription().c_str(), |
| 331 UTF16ToUTF8(contents->description_->text()).c_str()); |
| 332 } |
251 #endif | 333 #endif |
OLD | NEW |