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 "base/i18n/time_formatting.h" |
7 #include "chrome/browser/extensions/extension_service.h" | 7 #include "chrome/browser/extensions/extension_service.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/browser_window.h" | 10 #include "chrome/browser/ui/browser_window.h" |
11 #include "chrome/browser/ui/panels/panel.h" | 11 #include "chrome/browser/ui/panels/panel.h" |
12 #include "chrome/browser/ui/panels/panel_browser_frame_view.h" | 12 #include "chrome/browser/ui/panels/panel_browser_frame_view.h" |
13 #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_manager.h" | 14 #include "chrome/browser/ui/panels/panel_manager.h" |
15 #include "chrome/browser/ui/panels/panel_mouse_watcher_win.h" | 15 #include "chrome/browser/ui/panels/panel_mouse_watcher_win.h" |
| 16 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
16 #include "chrome/browser/web_applications/web_app.h" | 17 #include "chrome/browser/web_applications/web_app.h" |
17 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
18 #include "chrome/common/extensions/extension.h" | 19 #include "chrome/common/extensions/extension.h" |
19 #include "chrome/test/base/in_process_browser_test.h" | 20 #include "chrome/test/base/in_process_browser_test.h" |
| 21 #include "chrome/test/base/ui_test_utils.h" |
20 #include "grit/generated_resources.h" | 22 #include "grit/generated_resources.h" |
| 23 #include "net/base/net_util.h" |
21 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
23 #include "ui/base/animation/slide_animation.h" | 26 #include "ui/base/animation/slide_animation.h" |
24 #include "views/controls/button/image_button.h" | 27 #include "views/controls/button/image_button.h" |
25 #include "views/controls/button/menu_button.h" | 28 #include "views/controls/button/menu_button.h" |
26 #include "views/controls/image_view.h" | 29 #include "views/controls/image_view.h" |
27 #include "views/controls/label.h" | 30 #include "views/controls/label.h" |
28 #include "views/controls/link.h" | 31 #include "views/controls/link.h" |
29 #include "views/controls/textfield/textfield.h" | 32 #include "views/controls/textfield/textfield.h" |
30 | 33 |
| 34 const FilePath::CharType* kUpdateSizeTestFile = |
| 35 FILE_PATH_LITERAL("update-preferred-size.html"); |
| 36 |
31 class PanelBrowserViewTest : public InProcessBrowserTest { | 37 class PanelBrowserViewTest : public InProcessBrowserTest { |
32 public: | 38 public: |
33 PanelBrowserViewTest() : InProcessBrowserTest() { } | 39 PanelBrowserViewTest() : InProcessBrowserTest() { } |
34 | 40 |
35 virtual void SetUpCommandLine(CommandLine* command_line) { | 41 virtual void SetUpCommandLine(CommandLine* command_line) { |
| 42 EnableDOMAutomation(); |
36 command_line->AppendSwitch(switches::kEnablePanels); | 43 command_line->AppendSwitch(switches::kEnablePanels); |
37 } | 44 } |
38 | 45 |
39 protected: | 46 protected: |
40 struct MenuItem { | 47 struct MenuItem { |
41 int id; | 48 int id; |
42 bool enabled; | 49 bool enabled; |
43 }; | 50 }; |
44 | 51 |
45 class MockMouseWatcher : public PanelBrowserFrameView::MouseWatcher { | 52 class MockMouseWatcher : public PanelBrowserFrameView::MouseWatcher { |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 | 443 |
437 // Test that the attention is cleared. | 444 // Test that the attention is cleared. |
438 browser_view->StopDrawingAttention(); | 445 browser_view->StopDrawingAttention(); |
439 EXPECT_FALSE(browser_view->IsDrawingAttention()); | 446 EXPECT_FALSE(browser_view->IsDrawingAttention()); |
440 EXPECT_EQ(Panel::EXPANDED, panel->expansion_state()); | 447 EXPECT_EQ(Panel::EXPANDED, panel->expansion_state()); |
441 MessageLoop::current()->RunAllPending(); | 448 MessageLoop::current()->RunAllPending(); |
442 EXPECT_NE(attention_color, frame_view->title_label_->GetColor()); | 449 EXPECT_NE(attention_color, frame_view->title_label_->GetColor()); |
443 | 450 |
444 panel->Close(); | 451 panel->Close(); |
445 } | 452 } |
| 453 |
| 454 void TestUpdatePreferredSize() { |
| 455 // Create a test panel with tab contents loaded. |
| 456 Browser* panel_browser = Browser::CreateForApp(Browser::TYPE_PANEL, |
| 457 "PanelTest", |
| 458 gfx::Rect(0, 0, 100, 100), |
| 459 browser()->profile()); |
| 460 |
| 461 panel_browser->AddSelectedTabWithURL(GURL(chrome::kAboutBlankURL), |
| 462 PageTransition::START_PAGE); |
| 463 ui_test_utils::WaitForNavigation( |
| 464 &panel_browser->GetSelectedTabContents()->controller()); |
| 465 |
| 466 Panel* panel = static_cast<Panel*>(panel_browser->window()); |
| 467 panel->Show(); |
| 468 |
| 469 // Load the test page. |
| 470 ui_test_utils::NavigateToURL(panel_browser, |
| 471 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), |
| 472 FilePath(kUpdateSizeTestFile))); |
| 473 gfx::Rect initial_bounds = panel->GetBounds(); |
| 474 EXPECT_EQ(100, initial_bounds.width()); |
| 475 EXPECT_EQ(100, initial_bounds.height()); |
| 476 |
| 477 // Expand the test page. |
| 478 EXPECT_TRUE(ui_test_utils::ExecuteJavaScript( |
| 479 panel_browser->GetSelectedTabContents()->render_view_host(), |
| 480 std::wstring(), |
| 481 L"changeSize(50);")); |
| 482 |
| 483 // Wait till the bounds get changed. |
| 484 gfx::Rect bounds_on_grow; |
| 485 while ((bounds_on_grow = panel->GetBounds()) == initial_bounds) { |
| 486 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
| 487 MessageLoop::current()->RunAllPending(); |
| 488 } |
| 489 EXPECT_GT(bounds_on_grow.width(), initial_bounds.width()); |
| 490 EXPECT_EQ(bounds_on_grow.height(), initial_bounds.height()); |
| 491 |
| 492 // Shrink the test page. |
| 493 EXPECT_TRUE(ui_test_utils::ExecuteJavaScript( |
| 494 panel_browser->GetSelectedTabContents()->render_view_host(), |
| 495 std::wstring(), |
| 496 L"changeSize(-30);")); |
| 497 |
| 498 // Wait till the bounds get changed. |
| 499 gfx::Rect bounds_on_shrink; |
| 500 while ((bounds_on_shrink = panel->GetBounds()) == bounds_on_grow) { |
| 501 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
| 502 MessageLoop::current()->RunAllPending(); |
| 503 } |
| 504 EXPECT_LT(bounds_on_shrink.width(), bounds_on_grow.width()); |
| 505 EXPECT_GT(bounds_on_shrink.width(), initial_bounds.width()); |
| 506 EXPECT_EQ(bounds_on_shrink.height(), initial_bounds.height()); |
| 507 |
| 508 panel->Close(); |
| 509 } |
446 }; | 510 }; |
447 | 511 |
448 // Panel is not supported for Linux view yet. | 512 // Panel is not supported for Linux view yet. |
449 #if !defined(OS_LINUX) || !defined(TOOLKIT_VIEWS) | 513 #if !defined(OS_LINUX) || !defined(TOOLKIT_VIEWS) |
450 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, CreatePanel) { | 514 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, CreatePanel) { |
451 PanelBrowserView* browser_view = CreatePanelBrowserView("PanelTest", | 515 PanelBrowserView* browser_view = CreatePanelBrowserView("PanelTest", |
452 SHOW_AS_ACTIVE); | 516 SHOW_AS_ACTIVE); |
453 PanelBrowserFrameView* frame_view = browser_view->GetFrameView(); | 517 PanelBrowserFrameView* frame_view = browser_view->GetFrameView(); |
454 | 518 |
455 // The bounds animation should not be triggered when the panel is up for the | 519 // The bounds animation should not be triggered when the panel is up for the |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 "http://home", "options.html"); | 815 "http://home", "options.html"); |
752 } | 816 } |
753 | 817 |
754 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, MinimizeAndRestore) { | 818 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, MinimizeAndRestore) { |
755 TestMinimizeAndRestore(); | 819 TestMinimizeAndRestore(); |
756 } | 820 } |
757 | 821 |
758 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, DrawAttention) { | 822 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, DrawAttention) { |
759 TestDrawAttention(); | 823 TestDrawAttention(); |
760 } | 824 } |
| 825 |
| 826 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, UpdatePreferredSize) { |
| 827 TestUpdatePreferredSize(); |
| 828 } |
761 #endif | 829 #endif |
OLD | NEW |