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