| OLD | NEW |
| 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 "chrome/browser/push_messaging/push_messaging_notification_manager.h" | 5 #include "chrome/browser/push_messaging/push_messaging_notification_manager.h" |
| 6 | 6 |
| 7 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 7 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 8 #include "chrome/test/base/testing_profile.h" | 8 #include "chrome/test/base/testing_profile.h" |
| 9 #include "content/public/browser/render_widget_host_view.h" |
| 9 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
| 10 #include "content/public/test/test_renderer_host.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "url/gurl.h" | 12 #include "url/gurl.h" |
| 13 | 13 |
| 14 class PushMessagingNotificationManagerTest | 14 class PushMessagingNotificationManagerTest |
| 15 : public ChromeRenderViewHostTestHarness {}; | 15 : public ChromeRenderViewHostTestHarness {}; |
| 16 | 16 |
| 17 TEST_F(PushMessagingNotificationManagerTest, IsTabVisible) { | 17 TEST_F(PushMessagingNotificationManagerTest, IsTabVisible) { |
| 18 PushMessagingNotificationManager manager(profile()); | 18 PushMessagingNotificationManager manager(profile()); |
| 19 GURL origin("https://google.com/"); | 19 GURL origin("https://google.com/"); |
| 20 GURL origin_with_path = origin.Resolve("/path/"); | 20 GURL origin_with_path = origin.Resolve("/path/"); |
| 21 NavigateAndCommit(origin_with_path); | 21 NavigateAndCommit(origin_with_path); |
| 22 | 22 |
| 23 EXPECT_FALSE(manager.IsTabVisible(profile(), nullptr, origin)); | 23 EXPECT_FALSE(manager.IsTabVisible(profile(), nullptr, origin)); |
| 24 EXPECT_FALSE(manager.IsTabVisible(profile(), web_contents(), | 24 EXPECT_FALSE(manager.IsTabVisible(profile(), web_contents(), |
| 25 GURL("https://chrome.com/"))); | 25 GURL("https://chrome.com/"))); |
| 26 EXPECT_TRUE(manager.IsTabVisible(profile(), web_contents(), origin)); | 26 EXPECT_TRUE(manager.IsTabVisible(profile(), web_contents(), origin)); |
| 27 | 27 |
| 28 content::RenderViewHostTester::For(rvh())->SimulateWasHidden(); | 28 web_contents()->GetRenderWidgetHostView()->Hide(); |
| 29 EXPECT_FALSE(manager.IsTabVisible(profile(), web_contents(), origin)); | 29 EXPECT_FALSE(manager.IsTabVisible(profile(), web_contents(), origin)); |
| 30 | 30 |
| 31 content::RenderViewHostTester::For(rvh())->SimulateWasShown(); | 31 web_contents()->GetRenderWidgetHostView()->Show(); |
| 32 EXPECT_TRUE(manager.IsTabVisible(profile(), web_contents(), origin)); | 32 EXPECT_TRUE(manager.IsTabVisible(profile(), web_contents(), origin)); |
| 33 } | 33 } |
| 34 | 34 |
| 35 TEST_F(PushMessagingNotificationManagerTest, IsTabVisibleViewSource) { | 35 TEST_F(PushMessagingNotificationManagerTest, IsTabVisibleViewSource) { |
| 36 PushMessagingNotificationManager manager(profile()); | 36 PushMessagingNotificationManager manager(profile()); |
| 37 | 37 |
| 38 GURL origin("https://google.com/"); | 38 GURL origin("https://google.com/"); |
| 39 GURL view_source_page("view-source:https://google.com/path/"); | 39 GURL view_source_page("view-source:https://google.com/path/"); |
| 40 | 40 |
| 41 NavigateAndCommit(view_source_page); | 41 NavigateAndCommit(view_source_page); |
| 42 | 42 |
| 43 ASSERT_EQ(view_source_page, web_contents()->GetVisibleURL()); | 43 ASSERT_EQ(view_source_page, web_contents()->GetVisibleURL()); |
| 44 EXPECT_TRUE(manager.IsTabVisible(profile(), web_contents(), origin)); | 44 EXPECT_TRUE(manager.IsTabVisible(profile(), web_contents(), origin)); |
| 45 | 45 |
| 46 content::RenderViewHostTester::For(rvh())->SimulateWasHidden(); | 46 web_contents()->GetRenderWidgetHostView()->Hide(); |
| 47 EXPECT_FALSE(manager.IsTabVisible(profile(), web_contents(), origin)); | 47 EXPECT_FALSE(manager.IsTabVisible(profile(), web_contents(), origin)); |
| 48 } | 48 } |
| OLD | NEW |