| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 "extensions/browser/app_window/native_app_window.h" | 5 #include "extensions/browser/app_window/native_app_window.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #import "base/mac/foundation_util.h" | 9 #import "base/mac/foundation_util.h" |
| 10 #import "base/mac/mac_util.h" | 10 #import "base/mac/mac_util.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 using extensions::AppWindow; | 37 using extensions::AppWindow; |
| 38 using extensions::PlatformAppBrowserTest; | 38 using extensions::PlatformAppBrowserTest; |
| 39 | 39 |
| 40 using ::testing::_; | 40 using ::testing::_; |
| 41 using ::testing::Invoke; | 41 using ::testing::Invoke; |
| 42 using ::testing::Return; | 42 using ::testing::Return; |
| 43 | 43 |
| 44 namespace { | 44 namespace { |
| 45 | 45 |
| 46 class AppWindowObserver : public extensions::AppWindowRegistry::Observer { | |
| 47 public: | |
| 48 AppWindowObserver(Profile* profile) | |
| 49 : registry_(extensions::AppWindowRegistry::Get(profile)) { | |
| 50 registry_->AddObserver(this); | |
| 51 } | |
| 52 | |
| 53 ~AppWindowObserver() override { registry_->RemoveObserver(this); } | |
| 54 | |
| 55 void Wait(int window_count) { | |
| 56 if (windows_added_count_ < window_count) { | |
| 57 windows_added_count_expected_ = window_count; | |
| 58 run_loop_.Run(); | |
| 59 } | |
| 60 } | |
| 61 | |
| 62 private: | |
| 63 void OnAppWindowAdded(AppWindow* app_window) override { | |
| 64 ++windows_added_count_; | |
| 65 if (windows_added_count_expected_ > 0 && | |
| 66 windows_added_count_ >= windows_added_count_expected_) { | |
| 67 run_loop_.Quit(); | |
| 68 } | |
| 69 } | |
| 70 | |
| 71 extensions::AppWindowRegistry* registry_; | |
| 72 int windows_added_count_ = 0; | |
| 73 int windows_added_count_expected_ = 0; | |
| 74 base::RunLoop run_loop_; | |
| 75 }; | |
| 76 | |
| 77 // The param selects whether to use ChromeNativeAppWindowViewsMac, otherwise it | 46 // The param selects whether to use ChromeNativeAppWindowViewsMac, otherwise it |
| 78 // will use NativeAppWindowCocoa. | 47 // will use NativeAppWindowCocoa. |
| 79 class NativeAppWindowCocoaBrowserTest | 48 class NativeAppWindowCocoaBrowserTest |
| 80 : public testing::WithParamInterface<bool>, | 49 : public testing::WithParamInterface<bool>, |
| 81 public PlatformAppBrowserTest { | 50 public PlatformAppBrowserTest { |
| 82 protected: | 51 protected: |
| 83 NativeAppWindowCocoaBrowserTest() {} | 52 NativeAppWindowCocoaBrowserTest() {} |
| 84 | 53 |
| 85 void SetUpCommandLine(base::CommandLine* command_line) override { | 54 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 86 PlatformAppBrowserTest::SetUpCommandLine(command_line); | 55 PlatformAppBrowserTest::SetUpCommandLine(command_line); |
| 87 command_line->AppendSwitch( | 56 command_line->AppendSwitch( |
| 88 GetParam() ? switches::kEnableMacViewsNativeAppWindows | 57 GetParam() ? switches::kEnableMacViewsNativeAppWindows |
| 89 : switches::kDisableMacViewsNativeAppWindows); | 58 : switches::kDisableMacViewsNativeAppWindows); |
| 90 } | 59 } |
| 91 | 60 |
| 92 void SetUpAppWithWindows(int num_windows) { | 61 void SetUpAppWithWindows(int num_windows) { |
| 93 app_ = InstallExtension( | 62 app_ = InstallExtension( |
| 94 test_data_dir_.AppendASCII("platform_apps").AppendASCII("minimal"), 1); | 63 test_data_dir_.AppendASCII("platform_apps").AppendASCII("minimal"), 1); |
| 95 EXPECT_TRUE(app_); | 64 EXPECT_TRUE(app_); |
| 96 | 65 |
| 97 AppWindowObserver window_observer(profile()); | |
| 98 for (int i = 0; i < num_windows; ++i) { | 66 for (int i = 0; i < num_windows; ++i) { |
| 67 content::WindowedNotificationObserver app_loaded_observer( |
| 68 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 69 content::NotificationService::AllSources()); |
| 99 OpenApplication(AppLaunchParams( | 70 OpenApplication(AppLaunchParams( |
| 100 profile(), app_, extensions::LAUNCH_CONTAINER_NONE, | 71 profile(), app_, extensions::LAUNCH_CONTAINER_NONE, |
| 101 WindowOpenDisposition::NEW_WINDOW, extensions::SOURCE_TEST)); | 72 WindowOpenDisposition::NEW_WINDOW, extensions::SOURCE_TEST)); |
| 73 app_loaded_observer.Wait(); |
| 102 } | 74 } |
| 103 window_observer.Wait(num_windows); | |
| 104 } | 75 } |
| 105 | 76 |
| 106 const extensions::Extension* app_; | 77 const extensions::Extension* app_; |
| 107 | 78 |
| 108 private: | 79 private: |
| 109 DISALLOW_COPY_AND_ASSIGN(NativeAppWindowCocoaBrowserTest); | 80 DISALLOW_COPY_AND_ASSIGN(NativeAppWindowCocoaBrowserTest); |
| 110 }; | 81 }; |
| 111 | 82 |
| 112 } // namespace | 83 } // namespace |
| 113 | 84 |
| (...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 [expected_color getComponents:expected_components]; | 694 [expected_color getComponents:expected_components]; |
| 724 [color getComponents:color_components]; | 695 [color getComponents:color_components]; |
| 725 EXPECT_NEAR(expected_components[0], color_components[0], 0.01); | 696 EXPECT_NEAR(expected_components[0], color_components[0], 0.01); |
| 726 EXPECT_NEAR(expected_components[1], color_components[1], 0.01); | 697 EXPECT_NEAR(expected_components[1], color_components[1], 0.01); |
| 727 EXPECT_NEAR(expected_components[2], color_components[2], 0.01); | 698 EXPECT_NEAR(expected_components[2], color_components[2], 0.01); |
| 728 } | 699 } |
| 729 | 700 |
| 730 INSTANTIATE_TEST_CASE_P(NativeAppWindowCocoaBrowserTestInstance, | 701 INSTANTIATE_TEST_CASE_P(NativeAppWindowCocoaBrowserTestInstance, |
| 731 NativeAppWindowCocoaBrowserTest, | 702 NativeAppWindowCocoaBrowserTest, |
| 732 ::testing::Bool()); | 703 ::testing::Bool()); |
| OLD | NEW |