| 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 "base/test/test_timeouts.h" |
| 6 #include "base/threading/platform_thread.h" |
| 5 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 6 #include "chrome/app/chrome_command_ids.h" | 8 #include "chrome/app/chrome_command_ids.h" |
| 7 #include "chrome/browser/automation/automation_util.h" | 9 #include "chrome/browser/automation/automation_util.h" |
| 8 #include "chrome/browser/tab_contents/render_view_context_menu.h" | 10 #include "chrome/browser/tab_contents/render_view_context_menu.h" |
| 9 #include "chrome/browser/extensions/extension_test_message_listener.h" | 11 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 10 #include "chrome/browser/extensions/platform_app_browsertest_util.h" | 12 #include "chrome/browser/extensions/platform_app_browsertest_util.h" |
| 11 #include "chrome/browser/extensions/shell_window_registry.h" | 13 #include "chrome/browser/extensions/shell_window_registry.h" |
| 12 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/browser_tabstrip.h" | 15 #include "chrome/browser/ui/browser_tabstrip.h" |
| 14 #include "chrome/browser/ui/extensions/application_launch.h" | 16 #include "chrome/browser/ui/extensions/application_launch.h" |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 content::Source<content::WebContentsDelegate>(browser())); | 411 content::Source<content::WebContentsDelegate>(browser())); |
| 410 LoadAndLaunchPlatformApp("open_link"); | 412 LoadAndLaunchPlatformApp("open_link"); |
| 411 observer.Wait(); | 413 observer.Wait(); |
| 412 ASSERT_EQ(2, browser()->tab_count()); | 414 ASSERT_EQ(2, browser()->tab_count()); |
| 413 } | 415 } |
| 414 | 416 |
| 415 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MutationEventsDisabled) { | 417 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MutationEventsDisabled) { |
| 416 ASSERT_TRUE(RunPlatformAppTest("platform_apps/mutation_events")) << message_; | 418 ASSERT_TRUE(RunPlatformAppTest("platform_apps/mutation_events")) << message_; |
| 417 } | 419 } |
| 418 | 420 |
| 421 // Only implemented in GTK so far. |
| 422 #if defined(TOOLKIT_GTK) |
| 423 // Test that windows created with an id will remember and restore their |
| 424 // geometry when opening new windows. |
| 425 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, ShellWindowRestorePosition) { |
| 426 ExtensionTestMessageListener page2_listener("WaitForPage2", true); |
| 427 ExtensionTestMessageListener page3_listener("WaitForPage3", true); |
| 428 ExtensionTestMessageListener done_listener("Done1", false); |
| 429 ExtensionTestMessageListener done2_listener("Done2", false); |
| 430 ExtensionTestMessageListener done3_listener("Done3", false); |
| 431 |
| 432 ASSERT_TRUE(LoadAndLaunchPlatformApp("geometry")); |
| 433 |
| 434 // Wait for the app to be launched (although this is mostly to have a |
| 435 // message to reply to to let the script know it should create its second |
| 436 // window. |
| 437 ASSERT_TRUE(page2_listener.WaitUntilSatisfied()); |
| 438 |
| 439 // Wait for the first window to verify its geometry was correctly set |
| 440 // from the default* attributes passed to the create function. |
| 441 ASSERT_TRUE(done_listener.WaitUntilSatisfied()); |
| 442 |
| 443 // Programatically move and resize the window. |
| 444 ShellWindow* window = GetFirstShellWindow(); |
| 445 ASSERT_TRUE(window); |
| 446 gfx::Rect bounds(137, 143, 203, 187); |
| 447 window->GetBaseWindow()->SetBounds(bounds); |
| 448 |
| 449 #if defined(TOOLKIT_GTK) |
| 450 // TODO(mek): On GTK we have to wait for a roundtrip to the X server before |
| 451 // a resize actually happens: |
| 452 // "if you call gtk_window_resize() then immediately call |
| 453 // gtk_window_get_size(), the size won't have taken effect yet. After the |
| 454 // window manager processes the resize request, GTK+ receives notification |
| 455 // that the size has changed via a configure event, and the size of the |
| 456 // window gets updated." |
| 457 // Because of this we have to wait for an unknown time for the resize to |
| 458 // actually take effect. So wait some time or until the resize got |
| 459 // handled. |
| 460 base::TimeTicks end_time = base::TimeTicks::Now() + |
| 461 TestTimeouts::action_timeout(); |
| 462 while (base::TimeTicks::Now() < end_time && |
| 463 bounds != window->GetBaseWindow()->GetBounds()) { |
| 464 content::RunAllPendingInMessageLoop(); |
| 465 } |
| 466 |
| 467 // In the GTK ShellWindow implementation there also is a delay between |
| 468 // getting the correct bounds and it calling SaveWindowPosition, so call that |
| 469 // method explicitly to make sure the value was stored. |
| 470 window->SaveWindowPosition(); |
| 471 #endif // defined(TOOLKIT_GTK) |
| 472 |
| 473 // Make sure the window was properly moved&resized. |
| 474 ASSERT_EQ(bounds, window->GetBaseWindow()->GetBounds()); |
| 475 |
| 476 // Tell javascript to open a second window. |
| 477 page2_listener.Reply("continue"); |
| 478 |
| 479 // Wait for javascript to verify that the second window got the updated |
| 480 // coordinates, ignoring the default coordinates passed to the create method. |
| 481 ASSERT_TRUE(done2_listener.WaitUntilSatisfied()); |
| 482 |
| 483 // Tell javascript to open a third window. |
| 484 page3_listener.Reply("continue"); |
| 485 |
| 486 // Wait for javascript to verify that the third window got the restored size |
| 487 // and explicitly specified coordinates. |
| 488 ASSERT_TRUE(done3_listener.WaitUntilSatisfied()); |
| 489 } |
| 490 #endif // defined(TOOLKIT_GTK) |
| 491 |
| 419 } // namespace extensions | 492 } // namespace extensions |
| OLD | NEW |