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 "content/public/browser/notification_details.h" | 9 #include "content/public/browser/notification_details.h" |
10 #include "content/public/browser/notification_observer.h" | 10 #include "content/public/browser/notification_observer.h" |
11 #include "content/public/browser/notification_registrar.h" | 11 #include "content/public/browser/notification_registrar.h" |
12 #include "content/public/browser/notification_service.h" | 12 #include "content/public/browser/notification_service.h" |
13 #include "content/public/test/test_browser_thread_bundle.h" | 13 #include "content/public/test/test_browser_thread_bundle.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 | 15 |
16 class TestUpgradeDetectorImpl : public UpgradeDetectorImpl { | 16 class TestUpgradeDetectorImpl : public UpgradeDetectorImpl { |
17 public: | 17 public: |
18 TestUpgradeDetectorImpl() : trigger_critical_update_call_count_(0) {} | 18 TestUpgradeDetectorImpl() : trigger_critical_update_call_count_(0) {} |
19 virtual ~TestUpgradeDetectorImpl() {} | 19 virtual ~TestUpgradeDetectorImpl() {} |
20 | 20 |
21 // Methods exposed for testing. | 21 // Methods exposed for testing. |
22 using UpgradeDetectorImpl::OnExperimentChangesDetected; | 22 using UpgradeDetectorImpl::OnExperimentChangesDetected; |
23 using UpgradeDetectorImpl::NotifyOnUpgradeWithTimePassed; | 23 using UpgradeDetectorImpl::NotifyOnUpgradeWithTimePassed; |
24 | 24 |
25 // UpgradeDetector: | 25 // UpgradeDetector: |
26 virtual void TriggerCriticalUpdate() OVERRIDE { | 26 virtual void TriggerCriticalUpdate() override { |
27 trigger_critical_update_call_count_++; | 27 trigger_critical_update_call_count_++; |
28 } | 28 } |
29 | 29 |
30 int trigger_critical_update_call_count() const { | 30 int trigger_critical_update_call_count() const { |
31 return trigger_critical_update_call_count_; | 31 return trigger_critical_update_call_count_; |
32 } | 32 } |
33 | 33 |
34 private: | 34 private: |
35 // How many times TriggerCriticalUpdate() has been called. Expected to either | 35 // How many times TriggerCriticalUpdate() has been called. Expected to either |
36 // be 0 or 1. | 36 // be 0 or 1. |
(...skipping 12 matching lines...) Expand all Loading... |
49 } | 49 } |
50 | 50 |
51 const std::vector<int>& notifications_received() const { | 51 const std::vector<int>& notifications_received() const { |
52 return notifications_received_; | 52 return notifications_received_; |
53 } | 53 } |
54 | 54 |
55 private: | 55 private: |
56 // content::NotificationObserver: | 56 // content::NotificationObserver: |
57 virtual void Observe(int type, | 57 virtual void Observe(int type, |
58 const content::NotificationSource& source, | 58 const content::NotificationSource& source, |
59 const content::NotificationDetails& details) OVERRIDE { | 59 const content::NotificationDetails& details) override { |
60 notifications_received_.push_back(type); | 60 notifications_received_.push_back(type); |
61 } | 61 } |
62 | 62 |
63 // Registrar for listening to notifications. | 63 // Registrar for listening to notifications. |
64 content::NotificationRegistrar registrar_; | 64 content::NotificationRegistrar registrar_; |
65 | 65 |
66 // Keeps track of the number and types of notifications that were received. | 66 // Keeps track of the number and types of notifications that were received. |
67 std::vector<int> notifications_received_; | 67 std::vector<int> notifications_received_; |
68 | 68 |
69 DISALLOW_COPY_AND_ASSIGN(TestUpgradeNotificationListener); | 69 DISALLOW_COPY_AND_ASSIGN(TestUpgradeNotificationListener); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 EXPECT_FALSE(detector.notify_upgrade()); | 103 EXPECT_FALSE(detector.notify_upgrade()); |
104 EXPECT_TRUE(notifications_listener.notifications_received().empty()); | 104 EXPECT_TRUE(notifications_listener.notifications_received().empty()); |
105 | 105 |
106 detector.NotifyOnUpgradeWithTimePassed(base::TimeDelta::FromDays(30)); | 106 detector.NotifyOnUpgradeWithTimePassed(base::TimeDelta::FromDays(30)); |
107 EXPECT_TRUE(detector.notify_upgrade()); | 107 EXPECT_TRUE(detector.notify_upgrade()); |
108 ASSERT_EQ(1U, notifications_listener.notifications_received().size()); | 108 ASSERT_EQ(1U, notifications_listener.notifications_received().size()); |
109 EXPECT_EQ(chrome::NOTIFICATION_UPGRADE_RECOMMENDED, | 109 EXPECT_EQ(chrome::NOTIFICATION_UPGRADE_RECOMMENDED, |
110 notifications_listener.notifications_received().front()); | 110 notifications_listener.notifications_received().front()); |
111 EXPECT_EQ(1, detector.trigger_critical_update_call_count()); | 111 EXPECT_EQ(1, detector.trigger_critical_update_call_count()); |
112 } | 112 } |
OLD | NEW |