Chromium Code Reviews| Index: chrome/browser/metrics/desktop_engagement/chrome_visibility_observer_browsertest.cc |
| diff --git a/chrome/browser/metrics/desktop_engagement/chrome_visibility_observer_browsertest.cc b/chrome/browser/metrics/desktop_engagement/chrome_visibility_observer_browsertest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f01793878c750026f28ee2ec6d51d3c9246582a5 |
| --- /dev/null |
| +++ b/chrome/browser/metrics/desktop_engagement/chrome_visibility_observer_browsertest.cc |
| @@ -0,0 +1,48 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/metrics/desktop_engagement/chrome_visibility_observer.h" |
| + |
| +#include "base/memory/singleton.h" |
| +#include "chrome/browser/chrome_notification_types.h" |
| +#include "chrome/browser/ui/browser.h" |
| +#include "chrome/browser/ui/browser_list.h" |
| +#include "chrome/test/base/in_process_browser_test.h" |
| +#include "chrome/test/base/ui_test_utils.h" |
| +#include "content/public/browser/notification_service.h" |
| +#include "content/public/test/test_utils.h" |
| + |
| +// Mock class for |ChromeVisibilityObserver| for testing. |
| +class MockChromeVisibilityObserver : public metrics::ChromeVisibilityObserver { |
| + public: |
| + MockChromeVisibilityObserver() : is_active_(false) {} |
| + |
| + bool IsActive() { return is_active_; } |
|
Alexei Svitkine (slow)
2016/07/26 22:00:40
bool is_active() const
Same for other accessors i
gayane -on leave until 09-2017
2016/07/27 21:10:25
Done.
|
| + |
| + private: |
| + void SendVisibilityChangeEvent(bool active) override { is_active_ = active; } |
| + |
| + bool is_active_; |
|
Alexei Svitkine (slow)
2016/07/26 22:00:40
Add an empty line below this.
gayane -on leave until 09-2017
2016/07/27 21:10:24
Done.
|
| + DISALLOW_COPY_AND_ASSIGN(MockChromeVisibilityObserver); |
| +}; |
| + |
| +class ChromeVisibilityObserverBrowserTest : public InProcessBrowserTest {}; |
| + |
| +IN_PROC_BROWSER_TEST_F(ChromeVisibilityObserverBrowserTest, VisibilityTest) { |
| + MockChromeVisibilityObserver observer; |
| + |
| + EXPECT_FALSE(observer.IsActive()); |
| + Browser* new_browser = CreateBrowser(browser()->profile()); |
| + EXPECT_TRUE(observer.IsActive()); |
| + |
| + Browser* incognito_browser = CreateIncognitoBrowser(); |
| + EXPECT_TRUE(observer.IsActive()); |
| + |
| + CloseBrowserSynchronously(incognito_browser); |
| + EXPECT_TRUE(observer.IsActive()); |
| + |
| + CloseBrowserSynchronously(new_browser); |
| + CloseBrowserSynchronously(browser()); |
| + EXPECT_FALSE(observer.IsActive()); |
| +} |