| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/string_number_conversions.h" | 5 #include "base/string_number_conversions.h" |
| 6 #include "chrome/browser/extensions/extension_test_message_listener.h" | 6 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 7 #include "chrome/browser/extensions/platform_app_browsertest_util.h" | 7 #include "chrome/browser/extensions/platform_app_browsertest_util.h" |
| 8 #include "chrome/browser/extensions/shell_window_registry.h" |
| 9 #include "chrome/browser/ui/base_window.h" |
| 10 #include "chrome/browser/ui/browser.h" |
| 8 #include "chrome/browser/ui/extensions/native_app_window.h" | 11 #include "chrome/browser/ui/extensions/native_app_window.h" |
| 9 #include "chrome/browser/ui/extensions/shell_window.h" | 12 #include "chrome/browser/ui/extensions/shell_window.h" |
| 13 #include "chrome/test/base/testing_profile.h" |
| 10 #include "ui/gfx/rect.h" | 14 #include "ui/gfx/rect.h" |
| 11 | 15 |
| 16 namespace { |
| 17 |
| 18 class TestShellWindowRegistryObserver |
| 19 : public extensions::ShellWindowRegistry::Observer { |
| 20 public: |
| 21 explicit TestShellWindowRegistryObserver(Profile* profile) |
| 22 : profile_(profile), |
| 23 icon_updates_(0) { |
| 24 extensions::ShellWindowRegistry::Get(profile_)->AddObserver(this); |
| 25 } |
| 26 virtual ~TestShellWindowRegistryObserver() { |
| 27 extensions::ShellWindowRegistry::Get(profile_)->RemoveObserver(this); |
| 28 } |
| 29 |
| 30 // Overridden from ShellWindowRegistry::Observer: |
| 31 virtual void OnShellWindowAdded(ShellWindow* shell_window) {} |
| 32 virtual void OnShellWindowIconChanged(ShellWindow* shell_window) { |
| 33 ++icon_updates_; |
| 34 } |
| 35 virtual void OnShellWindowRemoved(ShellWindow* shell_window) { |
| 36 } |
| 37 |
| 38 int icon_updates() { return icon_updates_; } |
| 39 |
| 40 private: |
| 41 Profile* profile_; |
| 42 int icon_updates_; |
| 43 |
| 44 DISALLOW_COPY_AND_ASSIGN(TestShellWindowRegistryObserver); |
| 45 }; |
| 46 |
| 47 } // namespace |
| 48 |
| 12 namespace extensions { | 49 namespace extensions { |
| 13 | 50 |
| 14 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiBounds) { | 51 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiBounds) { |
| 15 ExtensionTestMessageListener background_listener("background_ok", false); | 52 ExtensionTestMessageListener background_listener("background_ok", false); |
| 16 ExtensionTestMessageListener ready_listener("ready", true /* will_reply */); | 53 ExtensionTestMessageListener ready_listener("ready", true /* will_reply */); |
| 17 ExtensionTestMessageListener success_listener("success", false); | 54 ExtensionTestMessageListener success_listener("success", false); |
| 18 | 55 |
| 19 LoadAndLaunchPlatformApp("windows_api_bounds"); | 56 LoadAndLaunchPlatformApp("windows_api_bounds"); |
| 20 ASSERT_TRUE(background_listener.WaitUntilSatisfied()); | 57 ASSERT_TRUE(background_listener.WaitUntilSatisfied()); |
| 21 ASSERT_TRUE(ready_listener.WaitUntilSatisfied()); | 58 ASSERT_TRUE(ready_listener.WaitUntilSatisfied()); |
| 22 ShellWindow* window = GetFirstShellWindow(); | 59 ShellWindow* window = GetFirstShellWindow(); |
| 23 | 60 |
| 24 gfx::Rect new_bounds(100, 200, 300, 400); | 61 gfx::Rect new_bounds(100, 200, 300, 400); |
| 25 window->GetBaseWindow()->SetBounds(new_bounds); | 62 window->GetBaseWindow()->SetBounds(new_bounds); |
| 26 | 63 |
| 27 // TODO(jeremya/asargent) figure out why in GTK the window doesn't end up | 64 // TODO(jeremya/asargent) figure out why in GTK the window doesn't end up |
| 28 // with exactly the bounds we set. Is it a bug in our shell window | 65 // with exactly the bounds we set. Is it a bug in our shell window |
| 29 // implementation? crbug.com/160252 | 66 // implementation? crbug.com/160252 |
| 30 #ifdef TOOLKIT_GTK | 67 #ifdef TOOLKIT_GTK |
| 31 int slop = 50; | 68 int slop = 50; |
| 32 #else | 69 #else |
| 33 int slop = 0; | 70 int slop = 0; |
| 34 #endif // !TOOLKIT_GTK | 71 #endif // !TOOLKIT_GTK |
| 35 | 72 |
| 36 ready_listener.Reply(base::IntToString(slop)); | 73 ready_listener.Reply(base::IntToString(slop)); |
| 37 ASSERT_TRUE(success_listener.WaitUntilSatisfied()); | 74 ASSERT_TRUE(success_listener.WaitUntilSatisfied()); |
| 38 } | 75 } |
| 39 | 76 |
| 77 // Tests chrome.app.window.setIcon. |
| 78 IN_PROC_BROWSER_TEST_F(ExperimentalPlatformAppBrowserTest, WindowsApiSetIcon) { |
| 79 scoped_ptr<TestShellWindowRegistryObserver> test_observer( |
| 80 new TestShellWindowRegistryObserver(browser()->profile())); |
| 81 ExtensionTestMessageListener listener("IconSet", false); |
| 82 LoadAndLaunchPlatformApp("windows_api_set_icon"); |
| 83 EXPECT_EQ(0, test_observer->icon_updates()); |
| 84 |
| 85 ASSERT_TRUE(listener.WaitUntilSatisfied()); |
| 86 |
| 87 ShellWindow* shell_window = GetFirstShellWindow(); |
| 88 ASSERT_TRUE(shell_window); |
| 89 EXPECT_NE(std::string::npos, |
| 90 shell_window->app_icon_url().spec().find("icon.png")); |
| 91 EXPECT_EQ(1, test_observer->icon_updates()); |
| 92 } |
| 93 |
| 40 // TODO(asargent) - Fix onMinimzed event on OSX (crbug.com/162793) and figure | 94 // TODO(asargent) - Fix onMinimzed event on OSX (crbug.com/162793) and figure |
| 41 // out what to do about the fact that minimize events don't work under ubuntu | 95 // out what to do about the fact that minimize events don't work under ubuntu |
| 42 // unity (crbug.com/162794 and https://bugs.launchpad.net/unity/+bug/998073). | 96 // unity (crbug.com/162794 and https://bugs.launchpad.net/unity/+bug/998073). |
| 43 #if defined(TOOLKIT_VIEWS) | 97 #if defined(TOOLKIT_VIEWS) |
| 44 | 98 |
| 45 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiProperties) { | 99 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiProperties) { |
| 46 EXPECT_TRUE( | 100 EXPECT_TRUE( |
| 47 RunExtensionTest("platform_apps/windows_api_properties")) << message_; | 101 RunExtensionTest("platform_apps/windows_api_properties")) << message_; |
| 48 } | 102 } |
| 49 | 103 |
| 50 #endif // defined(TOOLKIT_VIEWS) | 104 #endif // defined(TOOLKIT_VIEWS) |
| 51 | 105 |
| 52 } // namespace extensions | 106 } // namespace extensions |
| OLD | NEW |