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