1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/apps/app_browsertest_util.h"
6 #include "chrome/browser/profiles/profile.h"
7 #include "content/public/test/browser_test_utils.h"
8 #include "extensions/browser/process_manager.h"
9 #include "extensions/common/switches.h"
10 #include "extensions/test/extension_test_message_listener.h"
12 class WindowControlsTest
: public extensions::PlatformAppBrowserTest
{
14 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
15 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line
);
16 command_line
->AppendSwitch(extensions::switches::kEnableAppWindowControls
);
18 content::WebContents
* GetWebContentsForExtensionWindow(
19 const extensions::Extension
* extension
);
22 content::WebContents
* WindowControlsTest::GetWebContentsForExtensionWindow(
23 const extensions::Extension
* extension
) {
24 extensions::ProcessManager
* process_manager
=
25 extensions::ProcessManager::Get(profile());
27 // Lookup render view host for background page.
28 const extensions::ExtensionHost
* extension_host
=
29 process_manager
->GetBackgroundHostForExtension(extension
->id());
31 // Go through all active views, looking for the first window of the extension.
32 for (content::RenderFrameHost
* host
: process_manager
->GetAllFrames()) {
33 // Filter out views not part of this extension
34 if (process_manager
->GetExtensionForRenderFrameHost(host
) == extension
) {
35 // Filter out the background page view
36 content::WebContents
* web_contents
=
37 content::WebContents::FromRenderFrameHost(host
);
38 if (web_contents
!= extension_host
->web_contents())
45 IN_PROC_BROWSER_TEST_F(WindowControlsTest
, CloseControlWorks
) {
46 // Launch app and wait for window to show up
47 const extensions::Extension
* extension
=
48 LoadAndLaunchPlatformApp("window_controls/buttons", "window-opened");
50 // Find WebContents of window
51 content::WebContents
* web_contents
=
52 GetWebContentsForExtensionWindow(extension
);
53 ASSERT_TRUE(web_contents
!= NULL
);
55 // Send a left click on the "Close" button and wait for the close action
57 ExtensionTestMessageListener
window_closed("window-closed", false);
59 // Send mouse click somewhere inside the [x] button
60 const int controlOffset
= 25;
61 int x
= web_contents
->GetContainerBounds().size().width() - controlOffset
;
62 int y
= controlOffset
;
63 content::SimulateMouseClickAt(web_contents
,
65 blink::WebMouseEvent::ButtonLeft
,
68 ASSERT_TRUE(window_closed
.WaitUntilSatisfied());