Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(552)

Side by Side Diff: ash/metrics/user_metrics_recorder_unittest.cc

Issue 2825533003: mash: Prerequisites for removing ShelfDelegate. (Closed)
Patch Set: Expand CheckWindowAndItemPlacement comment. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "ash/metrics/user_metrics_recorder.h" 5 #include "ash/metrics/user_metrics_recorder.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "ash/login_status.h" 9 #include "ash/login_status.h"
10 #include "ash/public/cpp/config.h" 10 #include "ash/public/cpp/config.h"
11 #include "ash/shelf/shelf_model.h" 11 #include "ash/shelf/shelf_model.h"
12 #include "ash/shell.h" 12 #include "ash/shell.h"
13 #include "ash/shell_port.h" 13 #include "ash/shell_port.h"
14 #include "ash/test/ash_test_base.h" 14 #include "ash/test/ash_test_base.h"
15 #include "ash/test/test_shelf_delegate.h"
16 #include "ash/test/test_system_tray_delegate.h" 15 #include "ash/test/test_system_tray_delegate.h"
17 #include "ash/test/user_metrics_recorder_test_api.h" 16 #include "ash/test/user_metrics_recorder_test_api.h"
18 #include "ash/wm_window.h" 17 #include "ash/wm_window.h"
19 #include "base/test/histogram_tester.h" 18 #include "base/test/histogram_tester.h"
20 #include "ui/aura/window.h"
21 19
22 namespace ash { 20 namespace ash {
23 namespace { 21 namespace {
24 22
25 const char kAsh_NumberOfVisibleWindowsInPrimaryDisplay[] = 23 const char kAsh_NumberOfVisibleWindowsInPrimaryDisplay[] =
26 "Ash.NumberOfVisibleWindowsInPrimaryDisplay"; 24 "Ash.NumberOfVisibleWindowsInPrimaryDisplay";
27 25
28 const char kAsh_ActiveWindowShowTypeOverTime[] = 26 const char kAsh_ActiveWindowShowTypeOverTime[] =
29 "Ash.ActiveWindowShowTypeOverTime"; 27 "Ash.ActiveWindowShowTypeOverTime";
30 28
(...skipping 16 matching lines...) Expand all
47 void SetUp() override; 45 void SetUp() override;
48 void TearDown() override; 46 void TearDown() override;
49 47
50 // Sets the user login status. 48 // Sets the user login status.
51 void SetLoginStatus(LoginStatus login_status); 49 void SetLoginStatus(LoginStatus login_status);
52 50
53 // Sets the current user session to be active or inactive in a desktop 51 // Sets the current user session to be active or inactive in a desktop
54 // environment. 52 // environment.
55 void SetUserInActiveDesktopEnvironment(bool is_active); 53 void SetUserInActiveDesktopEnvironment(bool is_active);
56 54
57 // Creates an aura::Window.
58 aura::Window* CreateTestWindow();
59
60 test::UserMetricsRecorderTestAPI* user_metrics_recorder_test_api() { 55 test::UserMetricsRecorderTestAPI* user_metrics_recorder_test_api() {
61 return user_metrics_recorder_test_api_.get(); 56 return user_metrics_recorder_test_api_.get();
62 } 57 }
63 58
64 base::HistogramTester& histograms() { return histograms_; } 59 base::HistogramTester& histograms() { return histograms_; }
65 60
66 private: 61 private:
67 // Test API to access private members of the test target. 62 // Test API to access private members of the test target.
68 std::unique_ptr<test::UserMetricsRecorderTestAPI> 63 std::unique_ptr<test::UserMetricsRecorderTestAPI>
69 user_metrics_recorder_test_api_; 64 user_metrics_recorder_test_api_;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 SetLoginStatus(LoginStatus::USER); 97 SetLoginStatus(LoginStatus::USER);
103 ASSERT_TRUE( 98 ASSERT_TRUE(
104 user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment()); 99 user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment());
105 } else { 100 } else {
106 SetLoginStatus(LoginStatus::LOCKED); 101 SetLoginStatus(LoginStatus::LOCKED);
107 ASSERT_FALSE( 102 ASSERT_FALSE(
108 user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment()); 103 user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment());
109 } 104 }
110 } 105 }
111 106
112 aura::Window* UserMetricsRecorderTest::CreateTestWindow() {
113 aura::Window* window = CreateTestWindowInShellWithDelegateAndType(
114 nullptr, ui::wm::WINDOW_TYPE_NORMAL, 0, gfx::Rect());
115 return window;
116 }
117
118 // Verifies the return value of IsUserInActiveDesktopEnvironment() for the 107 // Verifies the return value of IsUserInActiveDesktopEnvironment() for the
119 // different login status values. 108 // different login status values.
120 TEST_F(UserMetricsRecorderTest, VerifyIsUserInActiveDesktopEnvironmentValues) { 109 TEST_F(UserMetricsRecorderTest, VerifyIsUserInActiveDesktopEnvironmentValues) {
121 SetLoginStatus(LoginStatus::NOT_LOGGED_IN); 110 SetLoginStatus(LoginStatus::NOT_LOGGED_IN);
122 EXPECT_FALSE( 111 EXPECT_FALSE(
123 user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment()); 112 user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment());
124 113
125 SetLoginStatus(LoginStatus::LOCKED); 114 SetLoginStatus(LoginStatus::LOCKED);
126 EXPECT_FALSE( 115 EXPECT_FALSE(
127 user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment()); 116 user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment());
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 histograms().ExpectTotalCount(kAsh_ActiveWindowShowTypeOverTime, 1); 175 histograms().ExpectTotalCount(kAsh_ActiveWindowShowTypeOverTime, 1);
187 } 176 }
188 177
189 // Verify the shelf item counts recorded by the 178 // Verify the shelf item counts recorded by the
190 // UserMetricsRecorder::RecordPeriodicMetrics() method. 179 // UserMetricsRecorder::RecordPeriodicMetrics() method.
191 TEST_F(UserMetricsRecorderTest, ValuesRecordedByRecordShelfItemCounts) { 180 TEST_F(UserMetricsRecorderTest, ValuesRecordedByRecordShelfItemCounts) {
192 // TODO: investigate failure in mash, http://crbug.com/695629. 181 // TODO: investigate failure in mash, http://crbug.com/695629.
193 if (Shell::GetAshConfig() == Config::MASH) 182 if (Shell::GetAshConfig() == Config::MASH)
194 return; 183 return;
195 184
196 test::TestShelfDelegate* test_shelf_delegate =
197 test::TestShelfDelegate::instance();
198 SetUserInActiveDesktopEnvironment(true); 185 SetUserInActiveDesktopEnvironment(true);
199 186
200 // Make sure the shelf contains the app list launcher button. 187 // Make sure the shelf contains the app list launcher button.
201 const ShelfItems& shelf_items = Shell::Get()->shelf_model()->items(); 188 ShelfModel* shelf_model = Shell::Get()->shelf_model();
202 ASSERT_EQ(1u, shelf_items.size()); 189 ASSERT_EQ(1u, shelf_model->items().size());
203 ASSERT_EQ(TYPE_APP_LIST, shelf_items[0].type); 190 ASSERT_EQ(TYPE_APP_LIST, shelf_model->items()[0].type);
204 191
205 aura::Window* pinned_window_with_app_id_1 = CreateTestWindow(); 192 ShelfItem shelf_item;
206 test_shelf_delegate->AddShelfItem(WmWindow::Get(pinned_window_with_app_id_1), 193 shelf_item.type = ash::TYPE_PINNED_APP;
207 "app_id_1"); 194 shelf_item.app_launch_id = AppLaunchId("app_id_1");
208 test_shelf_delegate->PinAppWithID("app_id_1"); 195 shelf_model->Add(shelf_item);
196 shelf_item.app_launch_id = AppLaunchId("app_id_2");
197 shelf_model->Add(shelf_item);
209 198
210 aura::Window* pinned_window_with_app_id_2 = CreateTestWindow(); 199 shelf_item.type = ash::TYPE_APP;
211 test_shelf_delegate->AddShelfItem(WmWindow::Get(pinned_window_with_app_id_2), 200 shelf_item.app_launch_id = AppLaunchId("app_id_3");
212 "app_id_2"); 201 shelf_model->Add(shelf_item);
213 test_shelf_delegate->PinAppWithID("app_id_2"); 202 shelf_item.app_launch_id = AppLaunchId("app_id_4");
214 203 shelf_model->Add(shelf_item);
215 aura::Window* unpinned_window_with_app_id_3 = CreateTestWindow(); 204 shelf_item.app_launch_id = AppLaunchId("app_id_5");
216 test_shelf_delegate->AddShelfItem( 205 shelf_model->Add(shelf_item);
217 WmWindow::Get(unpinned_window_with_app_id_3), "app_id_3");
218
219 aura::Window* unpinned_window_4 = CreateTestWindow();
220 test_shelf_delegate->AddShelfItem(WmWindow::Get(unpinned_window_4));
221
222 aura::Window* unpinned_window_5 = CreateTestWindow();
223 test_shelf_delegate->AddShelfItem(WmWindow::Get(unpinned_window_5));
224 206
225 user_metrics_recorder_test_api()->RecordPeriodicMetrics(); 207 user_metrics_recorder_test_api()->RecordPeriodicMetrics();
226 histograms().ExpectBucketCount(kAsh_Shelf_NumberOfItems, 5, 1); 208 histograms().ExpectBucketCount(kAsh_Shelf_NumberOfItems, 5, 1);
227 histograms().ExpectBucketCount(kAsh_Shelf_NumberOfPinnedItems, 2, 1); 209 histograms().ExpectBucketCount(kAsh_Shelf_NumberOfPinnedItems, 2, 1);
228 histograms().ExpectBucketCount(kAsh_Shelf_NumberOfUnpinnedItems, 3, 1); 210 histograms().ExpectBucketCount(kAsh_Shelf_NumberOfUnpinnedItems, 3, 1);
229 } 211 }
230 212
231 } // namespace ash 213 } // namespace ash
OLDNEW
« no previous file with comments | « ash/accelerators/accelerator_controller_unittest.cc ('k') | ash/shelf/shelf_application_menu_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698