15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file.
45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/apps/app_browsertest_util.h"
65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/test/base/interactive_test_utils.h"
703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "extensions/browser/app_window/native_app_window.h"
81320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "extensions/test/extension_test_message_listener.h"
91320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "extensions/test/result_catcher.h"
105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#if defined(OS_MACOSX) && !defined(OS_IOS)
125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/mac/mac_util.h"
135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif
145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
156e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#if defined(OS_WIN)
166e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include <windows.h>
176e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "ui/aura/window.h"
186e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "ui/aura/window_tree_host.h"
196e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "ui/views/widget/desktop_aura/desktop_window_tree_host_win.h"
206e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "ui/views/win/hwnd_message_handler_delegate.h"
216e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "ui/views/win/hwnd_util.h"
226e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#endif
236e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
241320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciusing extensions::AppWindow;
2503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)using extensions::NativeAppWindow;
265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Helper class that has to be created in the stack to check if the fullscreen
285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// setting of a NativeWindow has changed since the creation of the object.
295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class FullscreenChangeWaiter {
305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public:
315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  explicit FullscreenChangeWaiter(NativeAppWindow* window)
325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      : window_(window),
335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        initial_fullscreen_state_(window_->IsFullscreen()) {}
345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void Wait() {
365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    while (initial_fullscreen_state_ == window_->IsFullscreen())
375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      content::RunAllPendingInMessageLoop();
385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) private:
415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  NativeAppWindow* window_;
425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bool initial_fullscreen_state_;
435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(FullscreenChangeWaiter);
455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)};
465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class AppWindowInteractiveTest : public extensions::PlatformAppBrowserTest {
485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public:
495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bool RunAppWindowInteractiveTest(const char* testName) {
505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ExtensionTestMessageListener launched_listener("Launched", true);
51f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    LoadAndLaunchPlatformApp("window_api_interactive", &launched_listener);
525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    extensions::ResultCatcher catcher;
545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    launched_listener.Reply(testName);
555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    if (!catcher.GetNextResult()) {
575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      message_ = catcher.message();
585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      return false;
595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    }
605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return true;
625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bool SimulateKeyPress(ui::KeyboardCode key) {
655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return ui_test_utils::SendKeyPressToWindowSync(
665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        GetFirstAppWindow()->GetNativeWindow(),
675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        key,
685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        false,
695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        false,
705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        false,
715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        false);
725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // This method will wait until the application is able to ack a key event.
755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void WaitUntilKeyFocus() {
765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ExtensionTestMessageListener key_listener("KeyReceived", false);
775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    while (!key_listener.was_satisfied()) {
795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ASSERT_TRUE(SimulateKeyPress(ui::VKEY_Z));
805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      content::RunAllPendingInMessageLoop();
815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    }
825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
836e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
846e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // This test is a method so that we can test with each frame type.
856e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  void TestOuterBoundsHelper(const std::string& frame_type);
865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)};
875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, ESCLeavesFullscreenWindow) {
895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// This test is flaky on MacOS 10.6.
905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#if defined(OS_MACOSX) && !defined(OS_IOS)
915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (base::mac::IsOSSnowLeopard())
925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif
945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ExtensionTestMessageListener launched_listener("Launched", true);
96f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  LoadAndLaunchPlatformApp("leave_fullscreen", &launched_listener);
975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // We start by making sure the window is actually focused.
995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(
1005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      GetFirstAppWindow()->GetNativeWindow()));
1015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // When receiving the reply, the application will try to go fullscreen using
1035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // the Window API but there is no synchronous way to know if that actually
1045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // succeeded. Also, failure will not be notified. A failure case will only be
1055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // known with a timeout.
1065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  {
1075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    FullscreenChangeWaiter fs_changed(GetFirstAppWindow()->GetBaseWindow());
1085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    launched_listener.Reply("window");
1105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    fs_changed.Wait();
1125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
1135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Depending on the platform, going fullscreen might create an animation.
1155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // We want to make sure that the ESC key we will send next is actually going
1165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // to be received and the application might not receive key events during the
1175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // animation so we should wait for the key focus to be back.
1185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  WaitUntilKeyFocus();
1195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Same idea as above but for leaving fullscreen. Fullscreen mode should be
1215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // left when ESC is received.
1225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  {
1235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    FullscreenChangeWaiter fs_changed(GetFirstAppWindow()->GetBaseWindow());
1245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE));
1265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    fs_changed.Wait();
1285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
1295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
1305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
13103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#if defined(OS_MACOSX)
13203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)// http://crbug.com/406009
13303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#define MAYBE_ESCLeavesFullscreenDOM DISABLED_ESCLeavesFullscreenDOM
13403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#else
13503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#define MAYBE_ESCLeavesFullscreenDOM ESCLeavesFullscreenDOM
13603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#endif
13703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, MAYBE_ESCLeavesFullscreenDOM) {
1385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// This test is flaky on MacOS 10.6.
1395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#if defined(OS_MACOSX) && !defined(OS_IOS)
1405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (base::mac::IsOSSnowLeopard())
1415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
1425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif
1435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ExtensionTestMessageListener launched_listener("Launched", true);
145f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  LoadAndLaunchPlatformApp("leave_fullscreen", &launched_listener);
1465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // We start by making sure the window is actually focused.
1485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(
1495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      GetFirstAppWindow()->GetNativeWindow()));
1505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  launched_listener.Reply("dom");
1525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Because the DOM way to go fullscreen requires user gesture, we simulate a
1545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // key event to get the window entering in fullscreen mode. The reply will
1555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // make the window listen for the key event. The reply will be sent to the
1565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // renderer process before the keypress and should be received in that order.
1575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // When receiving the key event, the application will try to go fullscreen
1585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // using the Window API but there is no synchronous way to know if that
1595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // actually succeeded. Also, failure will not be notified. A failure case will
1605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // only be known with a timeout.
1615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  {
1625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    FullscreenChangeWaiter fs_changed(GetFirstAppWindow()->GetBaseWindow());
1635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    WaitUntilKeyFocus();
1655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ASSERT_TRUE(SimulateKeyPress(ui::VKEY_A));
1665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    fs_changed.Wait();
1685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
1695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Depending on the platform, going fullscreen might create an animation.
1715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // We want to make sure that the ESC key we will send next is actually going
1725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // to be received and the application might not receive key events during the
1735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // animation so we should wait for the key focus to be back.
1745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  WaitUntilKeyFocus();
1755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Same idea as above but for leaving fullscreen. Fullscreen mode should be
1775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // left when ESC is received.
1785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  {
1795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    FullscreenChangeWaiter fs_changed(GetFirstAppWindow()->GetBaseWindow());
1805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE));
1825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    fs_changed.Wait();
1845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
1855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
1865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
18703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#if defined(OS_MACOSX)
18803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)// http://crbug.com/406009
18903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#define MAYBE_ESCDoesNotLeaveFullscreenWindow DISABLED_ESCDoesNotLeaveFullscreenWindow
19003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#else
19103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#define MAYBE_ESCDoesNotLeaveFullscreenWindow ESCDoesNotLeaveFullscreenWindow
19203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#endif
1935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest,
19403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)                       MAYBE_ESCDoesNotLeaveFullscreenWindow) {
1955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// This test is flaky on MacOS 10.6.
1965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#if defined(OS_MACOSX) && !defined(OS_IOS)
1975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (base::mac::IsOSSnowLeopard())
1985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
1995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif
2005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ExtensionTestMessageListener launched_listener("Launched", true);
202f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  LoadAndLaunchPlatformApp("prevent_leave_fullscreen", &launched_listener);
2035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // We start by making sure the window is actually focused.
2055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(
2065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      GetFirstAppWindow()->GetNativeWindow()));
2075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // When receiving the reply, the application will try to go fullscreen using
2095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // the Window API but there is no synchronous way to know if that actually
2105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // succeeded. Also, failure will not be notified. A failure case will only be
2115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // known with a timeout.
2125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  {
2135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    FullscreenChangeWaiter fs_changed(GetFirstAppWindow()->GetBaseWindow());
2145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    launched_listener.Reply("window");
2165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    fs_changed.Wait();
2185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
2195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Depending on the platform, going fullscreen might create an animation.
2215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // We want to make sure that the ESC key we will send next is actually going
2225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // to be received and the application might not receive key events during the
2235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // animation so we should wait for the key focus to be back.
2245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  WaitUntilKeyFocus();
2255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE));
2275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ExtensionTestMessageListener second_key_listener("B_KEY_RECEIVED", false);
2295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_TRUE(SimulateKeyPress(ui::VKEY_B));
2315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_TRUE(second_key_listener.WaitUntilSatisfied());
2335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // We assume that at that point, if we had to leave fullscreen, we should be.
2355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // However, by nature, we can not guarantee that and given that we do test
2365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // that nothing happens, we might end up with random-success when the feature
2375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // is broken.
2385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_TRUE(GetFirstAppWindow()->GetBaseWindow()->IsFullscreen());
2395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
2405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest,
2425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                       ESCDoesNotLeaveFullscreenDOM) {
2435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// This test is flaky on MacOS 10.6.
2445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#if defined(OS_MACOSX) && !defined(OS_IOS)
2455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (base::mac::IsOSSnowLeopard())
2465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
2475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif
2485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ExtensionTestMessageListener launched_listener("Launched", true);
250f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  LoadAndLaunchPlatformApp("prevent_leave_fullscreen", &launched_listener);
2515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // We start by making sure the window is actually focused.
2535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(
2545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      GetFirstAppWindow()->GetNativeWindow()));
2555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  launched_listener.Reply("dom");
2575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Because the DOM way to go fullscreen requires user gesture, we simulate a
2595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // key event to get the window entering in fullscreen mode. The reply will
2605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // make the window listen for the key event. The reply will be sent to the
2615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // renderer process before the keypress and should be received in that order.
2625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // When receiving the key event, the application will try to go fullscreen
2635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // using the Window API but there is no synchronous way to know if that
2645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // actually succeeded. Also, failure will not be notified. A failure case will
2655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // only be known with a timeout.
2665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  {
2675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    FullscreenChangeWaiter fs_changed(GetFirstAppWindow()->GetBaseWindow());
2685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    WaitUntilKeyFocus();
2705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ASSERT_TRUE(SimulateKeyPress(ui::VKEY_A));
2715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    fs_changed.Wait();
2735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
2745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Depending on the platform, going fullscreen might create an animation.
2765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // We want to make sure that the ESC key we will send next is actually going
2775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // to be received and the application might not receive key events during the
2785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // animation so we should wait for the key focus to be back.
2795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  WaitUntilKeyFocus();
2805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE));
2825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ExtensionTestMessageListener second_key_listener("B_KEY_RECEIVED", false);
2845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_TRUE(SimulateKeyPress(ui::VKEY_B));
2865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_TRUE(second_key_listener.WaitUntilSatisfied());
2885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // We assume that at that point, if we had to leave fullscreen, we should be.
2905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // However, by nature, we can not guarantee that and given that we do test
2915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // that nothing happens, we might end up with random-success when the feature
2925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // is broken.
2935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_TRUE(GetFirstAppWindow()->GetBaseWindow()->IsFullscreen());
2945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
2955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
296a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// This test is duplicated from ESCDoesNotLeaveFullscreenWindow.
297a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// It runs the same test, but uses the old permission names: 'fullscreen'
298a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// and 'overrideEscFullscreen'.
299a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest,
300a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                       ESCDoesNotLeaveFullscreenOldPermission) {
301a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// This test is flaky on MacOS 10.6.
302a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#if defined(OS_MACOSX) && !defined(OS_IOS)
303a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (base::mac::IsOSSnowLeopard())
304a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return;
305a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#endif
306a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
307a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  ExtensionTestMessageListener launched_listener("Launched", true);
308f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  LoadAndLaunchPlatformApp("prevent_leave_fullscreen_old", &launched_listener);
309a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
310a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // We start by making sure the window is actually focused.
311a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(
312a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      GetFirstAppWindow()->GetNativeWindow()));
313a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
314a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // When receiving the reply, the application will try to go fullscreen using
315a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // the Window API but there is no synchronous way to know if that actually
316a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // succeeded. Also, failure will not be notified. A failure case will only be
317a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // known with a timeout.
318a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  {
319a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    FullscreenChangeWaiter fs_changed(GetFirstAppWindow()->GetBaseWindow());
320a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
321a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    launched_listener.Reply("window");
322a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
323a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    fs_changed.Wait();
324a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
325a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
326a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Depending on the platform, going fullscreen might create an animation.
327a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // We want to make sure that the ESC key we will send next is actually going
328a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // to be received and the application might not receive key events during the
329a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // animation so we should wait for the key focus to be back.
330a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  WaitUntilKeyFocus();
331a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
332a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE));
333a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
334a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  ExtensionTestMessageListener second_key_listener("B_KEY_RECEIVED", false);
335a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
336a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  ASSERT_TRUE(SimulateKeyPress(ui::VKEY_B));
337a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
338a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  ASSERT_TRUE(second_key_listener.WaitUntilSatisfied());
339a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
340a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // We assume that at that point, if we had to leave fullscreen, we should be.
341a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // However, by nature, we can not guarantee that and given that we do test
342a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // that nothing happens, we might end up with random-success when the feature
343a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // is broken.
344a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  EXPECT_TRUE(GetFirstAppWindow()->GetBaseWindow()->IsFullscreen());
345a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
346a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
3471320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#if defined(OS_MACOSX) || defined(OS_WIN)
3486e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// http://crbug.com/404081
3496e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#define MAYBE_TestInnerBounds DISABLED_TestInnerBounds
3506e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#else
3516e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#define MAYBE_TestInnerBounds TestInnerBounds
3526e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#endif
3536e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, MAYBE_TestInnerBounds) {
3546e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  ASSERT_TRUE(RunAppWindowInteractiveTest("testInnerBounds")) << message_;
3556e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)}
3566e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
3576e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)void AppWindowInteractiveTest::TestOuterBoundsHelper(
3586e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    const std::string& frame_type) {
3596e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  ExtensionTestMessageListener launched_listener("Launched", true);
3606e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  const extensions::Extension* app =
3616e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      LoadAndLaunchPlatformApp("outer_bounds", &launched_listener);
3626e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
3636e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  launched_listener.Reply(frame_type);
3646e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  launched_listener.Reset();
3656e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
3666e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
3671320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  AppWindow* window = GetFirstAppWindowForApp(app->id());
3686e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  gfx::Rect window_bounds;
3696e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  gfx::Size min_size, max_size;
3706e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
3716e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#if defined(OS_WIN)
3726e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // Get the bounds from the HWND.
3736e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  HWND hwnd = views::HWNDForNativeWindow(window->GetNativeWindow());
3746e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  RECT rect;
3756e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  ::GetWindowRect(hwnd, &rect);
3766e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  window_bounds = gfx::Rect(
3776e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
3786e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
3796e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // HWNDMessageHandler calls this when responding to WM_GETMINMAXSIZE, so it's
3806e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // the closest to what the window will see.
3816e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  views::HWNDMessageHandlerDelegate* host =
3826e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      static_cast<views::HWNDMessageHandlerDelegate*>(
3836e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)          static_cast<views::DesktopWindowTreeHostWin*>(
3846e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)              aura::WindowTreeHost::GetForAcceleratedWidget(hwnd)));
3856e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  host->GetMinMaxSize(&min_size, &max_size);
3866e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // Note that this does not include the the client area insets so we need to
3876e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // add them.
3886e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  gfx::Insets insets;
3896e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  host->GetClientAreaInsets(&insets);
3906e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  min_size = gfx::Size(min_size.width() + insets.left() + insets.right(),
3916e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)                       min_size.height() + insets.top() + insets.bottom());
3926e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  max_size = gfx::Size(
3936e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      max_size.width() ? max_size.width() + insets.left() + insets.right() : 0,
3946e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      max_size.height() ? max_size.height() + insets.top() + insets.bottom()
3956e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)                        : 0);
3966e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#endif  // defined(OS_WIN)
3976e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
3986e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // These match the values in the outer_bounds/test.js
3996e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  EXPECT_EQ(gfx::Rect(10, 11, 300, 301), window_bounds);
4006e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  EXPECT_EQ(window->GetBaseWindow()->GetBounds(), window_bounds);
4016e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  EXPECT_EQ(200, min_size.width());
4026e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  EXPECT_EQ(201, min_size.height());
4036e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  EXPECT_EQ(400, max_size.width());
4046e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  EXPECT_EQ(401, max_size.height());
4056e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)}
4066e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
4076e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// TODO(jackhou): Make this test work for other OSes.
4086e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#if !defined(OS_WIN)
4096e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#define MAYBE_TestOuterBoundsFrameChrome DISABLED_TestOuterBoundsFrameChrome
4106e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#define MAYBE_TestOuterBoundsFrameNone DISABLED_TestOuterBoundsFrameNone
4116e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#define MAYBE_TestOuterBoundsFrameColor DISABLED_TestOuterBoundsFrameColor
4126e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#else
4136e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#define MAYBE_TestOuterBoundsFrameChrome TestOuterBoundsFrameChrome
4146e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#define MAYBE_TestOuterBoundsFrameNone TestOuterBoundsFrameNone
4156e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#define MAYBE_TestOuterBoundsFrameColor TestOuterBoundsFrameColor
4166e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#endif
4176e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
4186e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// Test that the outer bounds match that of the native window.
4196e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest,
4206e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)                       MAYBE_TestOuterBoundsFrameChrome) {
4216e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  TestOuterBoundsHelper("chrome");
4226e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)}
4236e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest,
4246e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)                       MAYBE_TestOuterBoundsFrameNone) {
4256e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  TestOuterBoundsHelper("none");
4266e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)}
4276e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest,
4286e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)                       MAYBE_TestOuterBoundsFrameColor) {
4296e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  TestOuterBoundsHelper("color");
4306e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)}
4316e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
4325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// This test does not work on Linux Aura because ShowInactive() is not
4335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// implemented. See http://crbug.com/325142
4345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// It also does not work on Windows because of the document being focused even
4355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// though the window is not activated. See http://crbug.com/326986
4365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// It also does not work on MacOS because ::ShowInactive() ends up behaving like
4375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// ::Show() because of Cocoa conventions. See http://crbug.com/326987
4385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Those tests should be disabled on Linux GTK when they are enabled on the
4395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// other platforms, see http://crbug.com/328829
4405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#if (defined(OS_LINUX) && defined(USE_AURA)) || \
4415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    defined(OS_WIN) || defined(OS_MACOSX)
4425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#define MAYBE_TestCreate DISABLED_TestCreate
4435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#define MAYBE_TestShow DISABLED_TestShow
4445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#else
4455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#define MAYBE_TestCreate TestCreate
4465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#define MAYBE_TestShow TestShow
4475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif
4485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
4495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, MAYBE_TestCreate) {
4505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_TRUE(RunAppWindowInteractiveTest("testCreate")) << message_;
4515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
4525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
4535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, MAYBE_TestShow) {
4545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_TRUE(RunAppWindowInteractiveTest("testShow")) << message_;
4555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
45603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
45703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, TestDrawAttention) {
45803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  ASSERT_TRUE(RunAppWindowInteractiveTest("testDrawAttention")) << message_;
45903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)}
460