Chromium Code Reviews| 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 // Run pending checks. | |
|
Nico
2016/12/21 03:55:59
This isn't a good comment since it just answers "w
krasin1
2016/12/21 04:05:21
Good point. Done.
| |
| 95 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE); | |
| 91 } | 96 } |
| 92 | 97 |
| 93 TEST(UpgradeDetectorImplTest, VariationsCriticalChanges) { | 98 TEST(UpgradeDetectorImplTest, VariationsCriticalChanges) { |
| 94 content::TestBrowserThreadBundle bundle; | 99 content::TestBrowserThreadBundle bundle; |
| 95 | 100 |
| 96 TestUpgradeNotificationListener notifications_listener; | 101 TestUpgradeNotificationListener notifications_listener; |
| 97 TestUpgradeDetectorImpl detector; | 102 TestUpgradeDetectorImpl detector; |
| 98 EXPECT_FALSE(detector.notify_upgrade()); | 103 EXPECT_FALSE(detector.notify_upgrade()); |
| 99 EXPECT_TRUE(notifications_listener.notifications_received().empty()); | 104 EXPECT_TRUE(notifications_listener.notifications_received().empty()); |
| 100 | 105 |
| 101 detector.OnExperimentChangesDetected( | 106 detector.OnExperimentChangesDetected( |
| 102 variations::VariationsService::Observer::CRITICAL); | 107 variations::VariationsService::Observer::CRITICAL); |
| 103 EXPECT_FALSE(detector.notify_upgrade()); | 108 EXPECT_FALSE(detector.notify_upgrade()); |
| 104 EXPECT_TRUE(notifications_listener.notifications_received().empty()); | 109 EXPECT_TRUE(notifications_listener.notifications_received().empty()); |
| 105 | 110 |
| 106 detector.NotifyOnUpgradeWithTimePassed(base::TimeDelta::FromDays(30)); | 111 detector.NotifyOnUpgradeWithTimePassed(base::TimeDelta::FromDays(30)); |
| 107 EXPECT_TRUE(detector.notify_upgrade()); | 112 EXPECT_TRUE(detector.notify_upgrade()); |
| 108 ASSERT_EQ(1U, notifications_listener.notifications_received().size()); | 113 ASSERT_EQ(1U, notifications_listener.notifications_received().size()); |
| 109 EXPECT_EQ(chrome::NOTIFICATION_UPGRADE_RECOMMENDED, | 114 EXPECT_EQ(chrome::NOTIFICATION_UPGRADE_RECOMMENDED, |
| 110 notifications_listener.notifications_received().front()); | 115 notifications_listener.notifications_received().front()); |
| 111 EXPECT_EQ(1, detector.trigger_critical_update_call_count()); | 116 EXPECT_EQ(1, detector.trigger_critical_update_call_count()); |
| 117 | |
| 118 // Run pending checks. | |
| 119 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE); | |
|
Nico
2016/12/21 03:55:59
ditto
krasin1
2016/12/21 04:05:22
Done.
| |
| 112 } | 120 } |
| OLD | NEW |