| 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 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 | 355 |
| 349 // Test that the attention is cleared. | 356 // Test that the attention is cleared. |
| 350 browser_view->StopDrawingAttention(); | 357 browser_view->StopDrawingAttention(); |
| 351 EXPECT_FALSE(browser_view->IsDrawingAttention()); | 358 EXPECT_FALSE(browser_view->IsDrawingAttention()); |
| 352 EXPECT_EQ(Panel::EXPANDED, panel->expansion_state()); | 359 EXPECT_EQ(Panel::EXPANDED, panel->expansion_state()); |
| 353 MessageLoop::current()->RunAllPending(); | 360 MessageLoop::current()->RunAllPending(); |
| 354 EXPECT_NE(attention_color, frame_view->title_label_->GetColor()); | 361 EXPECT_NE(attention_color, frame_view->title_label_->GetColor()); |
| 355 | 362 |
| 356 panel->Close(); | 363 panel->Close(); |
| 357 } | 364 } |
| 365 |
| 366 void TestUpdatePreferredSize() { |
| 367 // Create a test panel with tab contents loaded. |
| 368 Browser* panel_browser = Browser::CreateForApp(Browser::TYPE_PANEL, |
| 369 "PanelTest", |
| 370 gfx::Rect(0, 0, 100, 100), |
| 371 browser()->profile()); |
| 372 |
| 373 panel_browser->AddSelectedTabWithURL(GURL(chrome::kAboutBlankURL), |
| 374 PageTransition::START_PAGE); |
| 375 ui_test_utils::WaitForNavigation( |
| 376 &panel_browser->GetSelectedTabContents()->controller()); |
| 377 |
| 378 Panel* panel = static_cast<Panel*>(panel_browser->window()); |
| 379 panel->Show(); |
| 380 |
| 381 // Load the test page. |
| 382 ui_test_utils::NavigateToURL(panel_browser, |
| 383 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), |
| 384 FilePath(kUpdateSizeTestFile))); |
| 385 gfx::Rect initial_bounds = panel->GetBounds(); |
| 386 EXPECT_EQ(100, initial_bounds.width()); |
| 387 EXPECT_EQ(100, initial_bounds.height()); |
| 388 |
| 389 // Expand the test page. |
| 390 EXPECT_TRUE(ui_test_utils::ExecuteJavaScript( |
| 391 panel_browser->GetSelectedTabContents()->render_view_host(), |
| 392 std::wstring(), |
| 393 L"changeSize(50);")); |
| 394 |
| 395 // Wait till the bounds get changed. |
| 396 gfx::Rect bounds_on_grow; |
| 397 while ((bounds_on_grow = panel->GetBounds()) == initial_bounds) { |
| 398 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
| 399 MessageLoop::current()->RunAllPending(); |
| 400 } |
| 401 EXPECT_GT(bounds_on_grow.width(), initial_bounds.width()); |
| 402 EXPECT_EQ(bounds_on_grow.height(), initial_bounds.height()); |
| 403 |
| 404 // Shrink the test page. |
| 405 EXPECT_TRUE(ui_test_utils::ExecuteJavaScript( |
| 406 panel_browser->GetSelectedTabContents()->render_view_host(), |
| 407 std::wstring(), |
| 408 L"changeSize(-30);")); |
| 409 |
| 410 // Wait till the bounds get changed. |
| 411 gfx::Rect bounds_on_shrink; |
| 412 while ((bounds_on_shrink = panel->GetBounds()) == bounds_on_grow) { |
| 413 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
| 414 MessageLoop::current()->RunAllPending(); |
| 415 } |
| 416 EXPECT_LT(bounds_on_shrink.width(), bounds_on_grow.width()); |
| 417 EXPECT_GT(bounds_on_shrink.width(), initial_bounds.width()); |
| 418 EXPECT_EQ(bounds_on_shrink.height(), initial_bounds.height()); |
| 419 |
| 420 panel->Close(); |
| 421 } |
| 358 }; | 422 }; |
| 359 | 423 |
| 360 // Panel is not supported for Linux view yet. | 424 // Panel is not supported for Linux view yet. |
| 361 #if !defined(OS_LINUX) || !defined(TOOLKIT_VIEWS) | 425 #if !defined(OS_LINUX) || !defined(TOOLKIT_VIEWS) |
| 362 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, CreatePanel) { | 426 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, CreatePanel) { |
| 363 PanelBrowserView* browser_view = CreatePanelBrowserView("PanelTest", | 427 PanelBrowserView* browser_view = CreatePanelBrowserView("PanelTest", |
| 364 SHOW_AS_ACTIVE); | 428 SHOW_AS_ACTIVE); |
| 365 PanelBrowserFrameView* frame_view = browser_view->GetFrameView(); | 429 PanelBrowserFrameView* frame_view = browser_view->GetFrameView(); |
| 366 | 430 |
| 367 // The bounds animation should not be triggered when the panel is up for the | 431 // The bounds animation should not be triggered when the panel is up for the |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 "http://home", "options.html"); | 551 "http://home", "options.html"); |
| 488 } | 552 } |
| 489 | 553 |
| 490 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, MinimizeAndRestore) { | 554 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, MinimizeAndRestore) { |
| 491 TestMinimizeAndRestore(); | 555 TestMinimizeAndRestore(); |
| 492 } | 556 } |
| 493 | 557 |
| 494 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, DrawAttention) { | 558 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, DrawAttention) { |
| 495 TestDrawAttention(); | 559 TestDrawAttention(); |
| 496 } | 560 } |
| 561 |
| 562 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, UpdatePreferredSize) { |
| 563 TestUpdatePreferredSize(); |
| 564 } |
| 497 #endif | 565 #endif |
| OLD | NEW |