| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/upgrade_detector_impl.h" | 5 #include "chrome/browser/upgrade_detector_impl.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "content/public/browser/browser_thread.h" |
| 10 #include "content/public/browser/notification_details.h" | 11 #include "content/public/browser/notification_details.h" |
| 11 #include "content/public/browser/notification_observer.h" | 12 #include "content/public/browser/notification_observer.h" |
| 12 #include "content/public/browser/notification_registrar.h" | 13 #include "content/public/browser/notification_registrar.h" |
| 13 #include "content/public/browser/notification_service.h" | 14 #include "content/public/browser/notification_service.h" |
| 14 #include "content/public/test/test_browser_thread_bundle.h" | 15 #include "content/public/test/test_browser_thread_bundle.h" |
| 16 #include "content/public/test/test_utils.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 18 |
| 17 class TestUpgradeDetectorImpl : public UpgradeDetectorImpl { | 19 class TestUpgradeDetectorImpl : public UpgradeDetectorImpl { |
| 18 public: | 20 public: |
| 19 TestUpgradeDetectorImpl() : trigger_critical_update_call_count_(0) {} | 21 TestUpgradeDetectorImpl() : trigger_critical_update_call_count_(0) {} |
| 20 ~TestUpgradeDetectorImpl() override {} | 22 ~TestUpgradeDetectorImpl() override {} |
| 21 | 23 |
| 22 // Methods exposed for testing. | 24 // Methods exposed for testing. |
| 23 using UpgradeDetectorImpl::OnExperimentChangesDetected; | 25 using UpgradeDetectorImpl::OnExperimentChangesDetected; |
| 24 using UpgradeDetectorImpl::NotifyOnUpgradeWithTimePassed; | 26 using UpgradeDetectorImpl::NotifyOnUpgradeWithTimePassed; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 variations::VariationsService::Observer::BEST_EFFORT); | 83 variations::VariationsService::Observer::BEST_EFFORT); |
| 82 EXPECT_FALSE(detector.notify_upgrade()); | 84 EXPECT_FALSE(detector.notify_upgrade()); |
| 83 EXPECT_TRUE(notifications_listener.notifications_received().empty()); | 85 EXPECT_TRUE(notifications_listener.notifications_received().empty()); |
| 84 | 86 |
| 85 detector.NotifyOnUpgradeWithTimePassed(base::TimeDelta::FromDays(30)); | 87 detector.NotifyOnUpgradeWithTimePassed(base::TimeDelta::FromDays(30)); |
| 86 EXPECT_TRUE(detector.notify_upgrade()); | 88 EXPECT_TRUE(detector.notify_upgrade()); |
| 87 ASSERT_EQ(1U, notifications_listener.notifications_received().size()); | 89 ASSERT_EQ(1U, notifications_listener.notifications_received().size()); |
| 88 EXPECT_EQ(chrome::NOTIFICATION_UPGRADE_RECOMMENDED, | 90 EXPECT_EQ(chrome::NOTIFICATION_UPGRADE_RECOMMENDED, |
| 89 notifications_listener.notifications_received().front()); | 91 notifications_listener.notifications_received().front()); |
| 90 EXPECT_EQ(0, detector.trigger_critical_update_call_count()); | 92 EXPECT_EQ(0, detector.trigger_critical_update_call_count()); |
| 93 |
| 94 // Execute tasks sent to FILE thread by |detector| referencing it |
| 95 // while it's still in scope. |
| 96 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE); |
| 91 } | 97 } |
| 92 | 98 |
| 93 TEST(UpgradeDetectorImplTest, VariationsCriticalChanges) { | 99 TEST(UpgradeDetectorImplTest, VariationsCriticalChanges) { |
| 94 content::TestBrowserThreadBundle bundle; | 100 content::TestBrowserThreadBundle bundle; |
| 95 | 101 |
| 96 TestUpgradeNotificationListener notifications_listener; | 102 TestUpgradeNotificationListener notifications_listener; |
| 97 TestUpgradeDetectorImpl detector; | 103 TestUpgradeDetectorImpl detector; |
| 98 EXPECT_FALSE(detector.notify_upgrade()); | 104 EXPECT_FALSE(detector.notify_upgrade()); |
| 99 EXPECT_TRUE(notifications_listener.notifications_received().empty()); | 105 EXPECT_TRUE(notifications_listener.notifications_received().empty()); |
| 100 | 106 |
| 101 detector.OnExperimentChangesDetected( | 107 detector.OnExperimentChangesDetected( |
| 102 variations::VariationsService::Observer::CRITICAL); | 108 variations::VariationsService::Observer::CRITICAL); |
| 103 EXPECT_FALSE(detector.notify_upgrade()); | 109 EXPECT_FALSE(detector.notify_upgrade()); |
| 104 EXPECT_TRUE(notifications_listener.notifications_received().empty()); | 110 EXPECT_TRUE(notifications_listener.notifications_received().empty()); |
| 105 | 111 |
| 106 detector.NotifyOnUpgradeWithTimePassed(base::TimeDelta::FromDays(30)); | 112 detector.NotifyOnUpgradeWithTimePassed(base::TimeDelta::FromDays(30)); |
| 107 EXPECT_TRUE(detector.notify_upgrade()); | 113 EXPECT_TRUE(detector.notify_upgrade()); |
| 108 ASSERT_EQ(1U, notifications_listener.notifications_received().size()); | 114 ASSERT_EQ(1U, notifications_listener.notifications_received().size()); |
| 109 EXPECT_EQ(chrome::NOTIFICATION_UPGRADE_RECOMMENDED, | 115 EXPECT_EQ(chrome::NOTIFICATION_UPGRADE_RECOMMENDED, |
| 110 notifications_listener.notifications_received().front()); | 116 notifications_listener.notifications_received().front()); |
| 111 EXPECT_EQ(1, detector.trigger_critical_update_call_count()); | 117 EXPECT_EQ(1, detector.trigger_critical_update_call_count()); |
| 118 |
| 119 // Execute tasks sent to FILE thread by |detector| referencing it |
| 120 // while it's still in scope. |
| 121 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE); |
| 112 } | 122 } |
| OLD | NEW |