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 |
46 // The param selects whether to use ChromeNativeAppWindowViewsMac, otherwise it | 77 // The param selects whether to use ChromeNativeAppWindowViewsMac, otherwise it |
47 // will use NativeAppWindowCocoa. | 78 // will use NativeAppWindowCocoa. |
48 class NativeAppWindowCocoaBrowserTest | 79 class NativeAppWindowCocoaBrowserTest |
49 : public testing::WithParamInterface<bool>, | 80 : public testing::WithParamInterface<bool>, |
50 public PlatformAppBrowserTest { | 81 public PlatformAppBrowserTest { |
51 protected: | 82 protected: |
52 NativeAppWindowCocoaBrowserTest() {} | 83 NativeAppWindowCocoaBrowserTest() {} |
53 | 84 |
54 void SetUpCommandLine(base::CommandLine* command_line) override { | 85 void SetUpCommandLine(base::CommandLine* command_line) override { |
55 PlatformAppBrowserTest::SetUpCommandLine(command_line); | 86 PlatformAppBrowserTest::SetUpCommandLine(command_line); |
56 command_line->AppendSwitch( | 87 command_line->AppendSwitch( |
57 GetParam() ? switches::kEnableMacViewsNativeAppWindows | 88 GetParam() ? switches::kEnableMacViewsNativeAppWindows |
58 : switches::kDisableMacViewsNativeAppWindows); | 89 : switches::kDisableMacViewsNativeAppWindows); |
59 } | 90 } |
60 | 91 |
61 void SetUpAppWithWindows(int num_windows) { | 92 void SetUpAppWithWindows(int num_windows) { |
62 app_ = InstallExtension( | 93 app_ = InstallExtension( |
63 test_data_dir_.AppendASCII("platform_apps").AppendASCII("minimal"), 1); | 94 test_data_dir_.AppendASCII("platform_apps").AppendASCII("minimal"), 1); |
64 EXPECT_TRUE(app_); | 95 EXPECT_TRUE(app_); |
65 | 96 |
| 97 AppWindowObserver window_observer(profile()); |
66 for (int i = 0; i < num_windows; ++i) { | 98 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()); | |
70 OpenApplication(AppLaunchParams( | 99 OpenApplication(AppLaunchParams( |
71 profile(), app_, extensions::LAUNCH_CONTAINER_NONE, | 100 profile(), app_, extensions::LAUNCH_CONTAINER_NONE, |
72 WindowOpenDisposition::NEW_WINDOW, extensions::SOURCE_TEST)); | 101 WindowOpenDisposition::NEW_WINDOW, extensions::SOURCE_TEST)); |
73 app_loaded_observer.Wait(); | |
74 } | 102 } |
| 103 window_observer.Wait(num_windows); |
75 } | 104 } |
76 | 105 |
77 const extensions::Extension* app_; | 106 const extensions::Extension* app_; |
78 | 107 |
79 private: | 108 private: |
80 DISALLOW_COPY_AND_ASSIGN(NativeAppWindowCocoaBrowserTest); | 109 DISALLOW_COPY_AND_ASSIGN(NativeAppWindowCocoaBrowserTest); |
81 }; | 110 }; |
82 | 111 |
83 } // namespace | 112 } // namespace |
84 | 113 |
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
694 [expected_color getComponents:expected_components]; | 723 [expected_color getComponents:expected_components]; |
695 [color getComponents:color_components]; | 724 [color getComponents:color_components]; |
696 EXPECT_NEAR(expected_components[0], color_components[0], 0.01); | 725 EXPECT_NEAR(expected_components[0], color_components[0], 0.01); |
697 EXPECT_NEAR(expected_components[1], color_components[1], 0.01); | 726 EXPECT_NEAR(expected_components[1], color_components[1], 0.01); |
698 EXPECT_NEAR(expected_components[2], color_components[2], 0.01); | 727 EXPECT_NEAR(expected_components[2], color_components[2], 0.01); |
699 } | 728 } |
700 | 729 |
701 INSTANTIATE_TEST_CASE_P(NativeAppWindowCocoaBrowserTestInstance, | 730 INSTANTIATE_TEST_CASE_P(NativeAppWindowCocoaBrowserTestInstance, |
702 NativeAppWindowCocoaBrowserTest, | 731 NativeAppWindowCocoaBrowserTest, |
703 ::testing::Bool()); | 732 ::testing::Bool()); |
OLD | NEW |