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" |
| 7 #include "chrome/browser/extensions/extension_service.h" |
6 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
7 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
8 #include "chrome/browser/ui/browser_window.h" | 10 #include "chrome/browser/ui/browser_window.h" |
| 11 #include "chrome/browser/ui/panels/about_panel_bubble.h" |
9 #include "chrome/browser/ui/panels/panel.h" | 12 #include "chrome/browser/ui/panels/panel.h" |
10 #include "chrome/browser/ui/panels/panel_browser_frame_view.h" | 13 #include "chrome/browser/ui/panels/panel_browser_frame_view.h" |
11 #include "chrome/browser/ui/panels/panel_browser_view.h" | 14 #include "chrome/browser/ui/panels/panel_browser_view.h" |
| 15 #include "chrome/browser/web_applications/web_app.h" |
12 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
| 17 #include "chrome/common/extensions/extension.h" |
13 #include "chrome/test/in_process_browser_test.h" | 18 #include "chrome/test/in_process_browser_test.h" |
| 19 #include "grit/generated_resources.h" |
| 20 #include "ui/base/l10n/l10n_util.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "views/controls/button/image_button.h" | 22 #include "views/controls/button/image_button.h" |
16 #include "views/controls/button/menu_button.h" | 23 #include "views/controls/button/menu_button.h" |
| 24 #include "views/controls/image_view.h" |
17 #include "views/controls/label.h" | 25 #include "views/controls/label.h" |
| 26 #include "views/controls/link.h" |
| 27 #include "views/controls/textfield/textfield.h" |
18 #include "views/controls/menu/menu_2.h" | 28 #include "views/controls/menu/menu_2.h" |
19 | 29 |
20 | |
21 class PanelBrowserViewTest : public InProcessBrowserTest { | 30 class PanelBrowserViewTest : public InProcessBrowserTest { |
22 public: | 31 public: |
23 PanelBrowserViewTest() : InProcessBrowserTest() { } | 32 PanelBrowserViewTest() : InProcessBrowserTest() { } |
24 | 33 |
25 virtual void SetUpCommandLine(CommandLine* command_line) { | 34 virtual void SetUpCommandLine(CommandLine* command_line) { |
26 command_line->AppendSwitch(switches::kEnablePanels); | 35 command_line->AppendSwitch(switches::kEnablePanels); |
27 } | 36 } |
28 | 37 |
29 protected: | 38 protected: |
30 PanelBrowserView* CreatePanelBrowserView(const std::string& panel_name) { | 39 PanelBrowserView* CreatePanelBrowserView(const std::string& panel_name) { |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 expected_delta_x_without_change, | 366 expected_delta_x_without_change, |
358 false); | 367 false); |
359 } | 368 } |
360 | 369 |
361 // Closes all panels. | 370 // Closes all panels. |
362 for (size_t i = 0; i < browser_view_count; ++i) { | 371 for (size_t i = 0; i < browser_view_count; ++i) { |
363 browser_views[i]->panel()->Close(); | 372 browser_views[i]->panel()->Close(); |
364 EXPECT_FALSE(browser_views[i]->panel()); | 373 EXPECT_FALSE(browser_views[i]->panel()); |
365 } | 374 } |
366 } | 375 } |
| 376 |
| 377 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, AboutPanelBubble) { |
| 378 ExtensionService* extension_service = |
| 379 browser()->GetProfile()->GetExtensionService(); |
| 380 |
| 381 // Create a testing extension. |
| 382 #if defined(OS_WIN) |
| 383 FilePath path(FILE_PATH_LITERAL("c:\\foo")); |
| 384 #else |
| 385 FilePath path(FILE_PATH_LITERAL("/foo")); |
367 #endif | 386 #endif |
| 387 DictionaryValue input_value; |
| 388 input_value.SetString(extension_manifest_keys::kVersion, "1.0.0.0"); |
| 389 input_value.SetString(extension_manifest_keys::kName, "Sample Extension"); |
| 390 input_value.SetString(extension_manifest_keys::kDescription, |
| 391 "Sample Description"); |
| 392 scoped_refptr<Extension> extension(Extension::Create(path, Extension::INVALID, |
| 393 input_value, Extension::STRICT_ERROR_CHECKS, NULL)); |
| 394 ASSERT_TRUE(extension.get()); |
| 395 extension_service->AddExtension(extension.get()); |
| 396 // Make sure that async task ExtensionPrefs::OnExtensionInstalled gets a |
| 397 // chance to be procesed. |
| 398 MessageLoop::current()->RunAllPending(); |
| 399 |
| 400 extension_service->extension_prefs()->OnExtensionInstalled( |
| 401 extension, Extension::ENABLED); |
| 402 |
| 403 // Create a panel with the app name that comes from the extension ID. |
| 404 PanelBrowserView* browser_view = CreatePanelBrowserView( |
| 405 web_app::GenerateApplicationNameFromExtensionId(extension->id())); |
| 406 |
| 407 AboutPanelBubble* bubble = AboutPanelBubble::Show( |
| 408 browser_view->GetWidget(), |
| 409 gfx::Rect(), |
| 410 BubbleBorder::BOTTOM_RIGHT, |
| 411 SkBitmap(), |
| 412 browser_view->browser()); |
| 413 AboutPanelBubble::AboutPanelBubbleView* contents = |
| 414 static_cast<AboutPanelBubble::AboutPanelBubbleView*>(bubble->contents()); |
| 415 |
| 416 // We should have the expected controls. |
| 417 EXPECT_EQ(6, contents->child_count()); |
| 418 EXPECT_TRUE(contents->Contains(contents->icon_)); |
| 419 EXPECT_TRUE(contents->Contains(contents->title_)); |
| 420 EXPECT_TRUE(contents->Contains(contents->install_date_)); |
| 421 EXPECT_TRUE(contents->Contains(contents->description_)); |
| 422 EXPECT_TRUE(contents->Contains(contents->uninstall_link_)); |
| 423 EXPECT_TRUE(contents->Contains(contents->report_abuse_link_)); |
| 424 |
| 425 // These controls should be visible. |
| 426 EXPECT_TRUE(contents->icon_->IsVisible()); |
| 427 EXPECT_TRUE(contents->title_->IsVisible()); |
| 428 EXPECT_TRUE(contents->install_date_->IsVisible()); |
| 429 EXPECT_TRUE(contents->description_->IsVisible()); |
| 430 EXPECT_TRUE(contents->uninstall_link_->IsVisible()); |
| 431 EXPECT_TRUE(contents->report_abuse_link_->IsVisible()); |
| 432 |
| 433 // Validate their layouts. |
| 434 EXPECT_GT(contents->title_->x(), contents->icon_->x()); |
| 435 EXPECT_GT(contents->title_->width(), 0); |
| 436 EXPECT_GT(contents->title_->height(), 0); |
| 437 EXPECT_EQ(contents->install_date_->x(), contents->title_->x()); |
| 438 EXPECT_GT(contents->install_date_->y(), contents->title_->y()); |
| 439 EXPECT_GT(contents->install_date_->width(), 0); |
| 440 EXPECT_GT(contents->install_date_->height(), 0); |
| 441 EXPECT_EQ(contents->description_->x(), contents->install_date_->x()); |
| 442 EXPECT_GT(contents->description_->y(), contents->install_date_->y()); |
| 443 EXPECT_GT(contents->description_->width(), 0); |
| 444 EXPECT_GT(contents->description_->height(), 0); |
| 445 EXPECT_EQ(contents->uninstall_link_->x(), contents->description_->x()); |
| 446 EXPECT_GT(contents->uninstall_link_->y(), contents->description_->y()); |
| 447 EXPECT_GT(contents->uninstall_link_->width(), 0); |
| 448 EXPECT_GT(contents->uninstall_link_->height(), 0); |
| 449 EXPECT_GT(contents->report_abuse_link_->x(), contents->uninstall_link_->x()); |
| 450 EXPECT_EQ(contents->report_abuse_link_->y(), contents->uninstall_link_->y()); |
| 451 EXPECT_GT(contents->report_abuse_link_->width(), 0); |
| 452 EXPECT_GT(contents->report_abuse_link_->height(), 0); |
| 453 |
| 454 // Validates the texts. |
| 455 base::Time install_time = |
| 456 extension_service->extension_prefs()->GetInstallTime(extension->id()); |
| 457 string16 time_text = l10n_util::GetStringFUTF16( |
| 458 IDS_ABOUT_PANEL_BUBBLE_EXTENSION_INSTALL_DATE, |
| 459 base::TimeFormatFriendlyDate( |
| 460 extension_service->extension_prefs()->GetInstallTime( |
| 461 extension->id()))); |
| 462 EXPECT_STREQ(UTF16ToUTF8(time_text).c_str(), |
| 463 WideToUTF8(contents->install_date_->GetText()).c_str()); |
| 464 EXPECT_STREQ(extension->description().c_str(), |
| 465 UTF16ToUTF8(contents->description_->text()).c_str()); |
| 466 } |
| 467 #endif |
OLD | NEW |