Chromium Code Reviews| 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 "chrome/app/chrome_command_ids.h" | 5 #include "chrome/app/chrome_command_ids.h" |
| 6 #include "chrome/browser/automation/automation_util.h" | 6 #include "chrome/browser/automation/automation_util.h" |
| 7 #include "chrome/browser/tab_contents/render_view_context_menu.h" | 7 #include "chrome/browser/tab_contents/render_view_context_menu.h" |
| 8 #include "chrome/browser/extensions/extension_test_message_listener.h" | 8 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 9 #include "chrome/browser/extensions/platform_app_browsertest_util.h" | 9 #include "chrome/browser/extensions/platform_app_browsertest_util.h" |
| 10 #include "chrome/browser/extensions/shell_window_registry.h" | 10 #include "chrome/browser/extensions/shell_window_registry.h" |
| 11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/browser_tabstrip.h" | 12 #include "chrome/browser/ui/browser_tabstrip.h" |
| 13 #include "chrome/browser/ui/extensions/application_launch.h" | 13 #include "chrome/browser/ui/extensions/application_launch.h" |
| 14 #include "chrome/browser/ui/extensions/shell_window.h" | 14 #include "chrome/browser/ui/extensions/shell_window.h" |
| 15 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
| 16 #include "chrome/test/base/ui_test_utils.h" | 16 #include "chrome/test/base/ui_test_utils.h" |
| 17 #include "content/public/browser/render_process_host.h" | 17 #include "content/public/browser/render_process_host.h" |
| 18 #include "base/threading/platform_thread.h" | |
| 18 | 19 |
| 19 using content::WebContents; | 20 using content::WebContents; |
| 20 | 21 |
| 21 namespace extensions { | 22 namespace extensions { |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 // Non-abstract RenderViewContextMenu class. | 25 // Non-abstract RenderViewContextMenu class. |
| 25 class PlatformAppContextMenu : public RenderViewContextMenu { | 26 class PlatformAppContextMenu : public RenderViewContextMenu { |
| 26 public: | 27 public: |
| 27 PlatformAppContextMenu(WebContents* web_contents, | 28 PlatformAppContextMenu(WebContents* web_contents, |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 335 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OpenLink) { | 336 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OpenLink) { |
| 336 ASSERT_TRUE(StartTestServer()); | 337 ASSERT_TRUE(StartTestServer()); |
| 337 content::WindowedNotificationObserver observer( | 338 content::WindowedNotificationObserver observer( |
| 338 chrome::NOTIFICATION_TAB_ADDED, | 339 chrome::NOTIFICATION_TAB_ADDED, |
| 339 content::Source<content::WebContentsDelegate>(browser())); | 340 content::Source<content::WebContentsDelegate>(browser())); |
| 340 LoadAndLaunchPlatformApp("open_link"); | 341 LoadAndLaunchPlatformApp("open_link"); |
| 341 observer.Wait(); | 342 observer.Wait(); |
| 342 ASSERT_EQ(2, browser()->tab_count()); | 343 ASSERT_EQ(2, browser()->tab_count()); |
| 343 } | 344 } |
| 344 | 345 |
| 346 // only implemented on linux so far | |
| 347 #if defined(OS_LINUX) | |
| 348 // Test that windows created with an id will remember and restore their | |
| 349 // geometry when opening new windows. | |
| 350 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, ShellWindowRestorePosition) { | |
| 351 ExtensionTestMessageListener page2_listener("WaitForPage2", true); | |
| 352 ExtensionTestMessageListener page3_listener("WaitForPage3", true); | |
| 353 ExtensionTestMessageListener done_listener("Done1", false); | |
| 354 ExtensionTestMessageListener done2_listener("Done2", false); | |
| 355 ExtensionTestMessageListener done3_listener("Done3", false); | |
| 356 | |
| 357 ASSERT_TRUE(LoadAndLaunchPlatformApp("geometry")); | |
| 358 | |
| 359 // Wait for the app to be launched (although this is mostly to have a | |
| 360 // message to reply to to let the script know it should create its second | |
| 361 // window. | |
| 362 ASSERT_TRUE(page2_listener.WaitUntilSatisfied()); | |
| 363 | |
| 364 // Wait for the first window to verify its geometry was correctly set | |
| 365 // from the default* attributes passed to the create function. | |
| 366 ASSERT_TRUE(done_listener.WaitUntilSatisfied()); | |
| 367 | |
| 368 // programatically move and resize the window | |
| 369 ShellWindow* window = GetFirstShellWindow(); | |
| 370 ASSERT_TRUE(window); | |
| 371 gfx::Rect bounds(137, 143, 203, 187); | |
| 372 window->GetBaseWindow()->SetBounds(bounds); | |
| 373 | |
| 374 // TODO(mek): there is a delay (and on linux an X roundtrip) between setting | |
| 375 // bounds for a window and being able to read back those same bounds. This | |
| 376 // seems to work to wait long enough, but there are probably still situations | |
| 377 // where timing still works out badly. | |
| 378 const base::TimeDelta kWaitTime = base::TimeDelta::FromSeconds(1); | |
| 379 base::TimeTicks end_time = base::TimeTicks::Now() + kWaitTime; | |
| 380 while (base::TimeTicks::Now() < end_time) { | |
| 381 content::RunAllPendingInMessageLoop(); | |
| 382 } | |
|
asargent_no_longer_on_chrome
2012/08/29 00:01:56
Instead of always waiting 1 second to read back th
| |
| 383 | |
| 384 // make sure the window was properly moved&resized | |
| 385 ASSERT_EQ(bounds, window->GetBaseWindow()->GetBounds()); | |
| 386 | |
| 387 // tell javascript to open a second window | |
| 388 page2_listener.Reply("continue"); | |
| 389 | |
| 390 // wait for javascript to verify that the second window got the updated | |
| 391 // coordinates, ignoring its default* create params. | |
| 392 ASSERT_TRUE(done2_listener.WaitUntilSatisfied()); | |
| 393 | |
| 394 | |
| 395 // tell javascript to open a third window | |
| 396 page3_listener.Reply("continue"); | |
| 397 | |
| 398 // wait for javascript to verify that the third window got the restored size | |
| 399 // and explicitly specified coordinates. | |
| 400 ASSERT_TRUE(done3_listener.WaitUntilSatisfied()); | |
| 401 } | |
| 402 #endif // defined(OS_LINUX) | |
| 403 | |
| 345 } // namespace extensions | 404 } // namespace extensions |
| OLD | NEW |