OLD | NEW |
| (Empty) |
1 // Copyright 2016 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. | |
4 | |
5 #include "chrome/browser/metrics/desktop_engagement/chrome_visibility_observer.h
" | |
6 | |
7 #include "base/memory/singleton.h" | |
8 #include "chrome/browser/chrome_notification_types.h" | |
9 #include "chrome/browser/ui/browser.h" | |
10 #include "chrome/browser/ui/browser_list.h" | |
11 #include "chrome/test/base/in_process_browser_test.h" | |
12 #include "chrome/test/base/ui_test_utils.h" | |
13 #include "content/public/browser/notification_service.h" | |
14 #include "content/public/test/test_utils.h" | |
15 | |
16 // Mock class for |ChromeVisibilityObserver| for testing. | |
17 class MockChromeVisibilityObserver : public metrics::ChromeVisibilityObserver { | |
18 public: | |
19 MockChromeVisibilityObserver() : is_active_(false) {} | |
20 | |
21 bool is_active() const { return is_active_; } | |
22 | |
23 private: | |
24 void SendVisibilityChangeEvent(bool active) override { is_active_ = active; } | |
25 | |
26 bool is_active_; | |
27 | |
28 DISALLOW_COPY_AND_ASSIGN(MockChromeVisibilityObserver); | |
29 }; | |
30 | |
31 class ChromeVisibilityObserverBrowserTest : public InProcessBrowserTest {}; | |
32 | |
33 IN_PROC_BROWSER_TEST_F(ChromeVisibilityObserverBrowserTest, VisibilityTest) { | |
34 MockChromeVisibilityObserver observer; | |
35 | |
36 EXPECT_FALSE(observer.is_active()); | |
37 Browser* new_browser = CreateBrowser(browser()->profile()); | |
38 EXPECT_TRUE(observer.is_active()); | |
39 | |
40 Browser* incognito_browser = CreateIncognitoBrowser(); | |
41 EXPECT_TRUE(observer.is_active()); | |
42 | |
43 CloseBrowserSynchronously(incognito_browser); | |
44 EXPECT_TRUE(observer.is_active()); | |
45 | |
46 CloseBrowserSynchronously(new_browser); | |
47 CloseBrowserSynchronously(browser()); | |
48 EXPECT_FALSE(observer.is_active()); | |
49 } | |
OLD | NEW |