This source file includes following definitions.
- SetUpCommandLine
- GetWebContentsForExtensionWindow
- IN_PROC_BROWSER_TEST_F
#include "chrome/browser/apps/app_browsertest_util.h"
#include "chrome/browser/extensions/extension_test_message_listener.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_switches.h"
#include "content/public/browser/web_contents_view.h"
#include "content/public/test/browser_test_utils.h"
#include "extensions/browser/process_manager.h"
class WindowControlsTest : public extensions::PlatformAppBrowserTest {
protected:
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line);
command_line->AppendSwitch(switches::kEnableAppWindowControls);
}
content::WebContents* GetWebContentsForExtensionWindow(
const extensions::Extension* extension);
};
content::WebContents* WindowControlsTest::GetWebContentsForExtensionWindow(
const extensions::Extension* extension) {
extensions::ProcessManager* process_manager =
extensions::ExtensionSystem::Get(profile())->process_manager();
const extensions::ExtensionHost* extension_host =
process_manager->GetBackgroundHostForExtension(extension->id());
content::RenderViewHost* background_view_host =
extension_host->render_view_host();
const extensions::ProcessManager::ViewSet all_views =
process_manager->GetAllViews();
extensions::ProcessManager::ViewSet::const_iterator it = all_views.begin();
for (; it != all_views.end(); ++it) {
content::RenderViewHost* host = *it;
if (process_manager->GetExtensionForRenderViewHost(host) == extension) {
if (host != background_view_host) {
content::WebContents* web_contents =
content::WebContents::FromRenderViewHost(host);
return web_contents;
}
}
}
return NULL;
}
IN_PROC_BROWSER_TEST_F(WindowControlsTest, CloseControlWorks) {
ExtensionTestMessageListener window_opened("window-opened", false);
const extensions::Extension* extension =
LoadAndLaunchPlatformApp("window_controls/buttons");
ASSERT_TRUE(window_opened.WaitUntilSatisfied());
content::WebContents* web_contents =
GetWebContentsForExtensionWindow(extension);
ASSERT_TRUE(web_contents != NULL);
ExtensionTestMessageListener window_closed("window-closed", false);
const int controlOffset = 25;
int x = web_contents->GetView()->GetContainerSize().width() - controlOffset;
int y = controlOffset;
content::SimulateMouseClickAt(web_contents,
0,
blink::WebMouseEvent::ButtonLeft,
gfx::Point(x, y));
ASSERT_TRUE(window_closed.WaitUntilSatisfied());
}