1 // Copyright 2014 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 "extensions/shell/browser/shell_native_app_window_aura.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "content/public/browser/browser_context.h"
9 #include "content/public/browser/notification_service.h"
10 #include "content/public/browser/web_contents.h"
11 #include "content/public/test/test_browser_context.h"
12 #include "content/public/test/test_browser_thread_bundle.h"
13 #include "extensions/browser/app_window/app_window.h"
14 #include "extensions/browser/app_window/test_app_window_contents.h"
15 #include "extensions/browser/extensions_test.h"
16 #include "extensions/common/extension.h"
17 #include "extensions/common/extension_builder.h"
18 #include "extensions/shell/browser/desktop_controller.h"
19 #include "extensions/shell/browser/shell_app_delegate.h"
20 #include "extensions/shell/browser/shell_app_window_client.h"
21 #include "ui/gfx/geometry/rect.h"
23 namespace extensions
{
25 class ShellNativeAppWindowAuraTest
: public ExtensionsTest
{
27 ShellNativeAppWindowAuraTest()
28 : notification_service_(content::NotificationService::Create()) {
29 AppWindowClient::Set(&app_window_client_
);
32 ~ShellNativeAppWindowAuraTest() override
{}
35 content::TestBrowserThreadBundle thread_bundle_
;
36 scoped_ptr
<content::NotificationService
> notification_service_
;
37 ShellAppWindowClient app_window_client_
;
40 TEST_F(ShellNativeAppWindowAuraTest
, Bounds
) {
41 // The BrowserContext used here must be destroyed before the thread bundle,
42 // because of destructors of things spawned from creating a WebContents.
43 scoped_ptr
<content::BrowserContext
> browser_context(
44 new content::TestBrowserContext
);
45 scoped_refptr
<Extension
> extension
=
47 .SetManifest(DictionaryBuilder()
48 .Set("name", "test extension")
50 .Set("manifest_version", 2))
53 AppWindow
* app_window
= new AppWindow(
54 browser_context
.get(), new ShellAppDelegate
, extension
.get());
55 content::WebContents
* web_contents
= content::WebContents::Create(
56 content::WebContents::CreateParams(browser_context
.get()));
57 app_window
->SetAppWindowContentsForTesting(
58 make_scoped_ptr(new TestAppWindowContents(web_contents
)));
60 AppWindow::BoundsSpecification window_spec
;
61 window_spec
.bounds
= gfx::Rect(100, 200, 300, 400);
62 AppWindow::CreateParams params
;
63 params
.window_spec
= window_spec
;
65 ShellNativeAppWindowAura
window(app_window
, params
);
67 gfx::Rect bounds
= window
.GetBounds();
68 EXPECT_EQ(window_spec
.bounds
, bounds
);
70 // Delete the AppWindow.
71 app_window
->OnNativeClose();
74 } // namespace extensions