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 ~TestUpgradeDetectorImpl() override {} |
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 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. |
37 int trigger_critical_update_call_count_; | 37 int trigger_critical_update_call_count_; |
38 | 38 |
39 DISALLOW_COPY_AND_ASSIGN(TestUpgradeDetectorImpl); | 39 DISALLOW_COPY_AND_ASSIGN(TestUpgradeDetectorImpl); |
40 }; | 40 }; |
41 | 41 |
42 class TestUpgradeNotificationListener : public content::NotificationObserver { | 42 class TestUpgradeNotificationListener : public content::NotificationObserver { |
43 public: | 43 public: |
44 TestUpgradeNotificationListener() { | 44 TestUpgradeNotificationListener() { |
45 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED, | 45 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED, |
46 content::NotificationService::AllSources()); | 46 content::NotificationService::AllSources()); |
47 } | 47 } |
48 virtual ~TestUpgradeNotificationListener() { | 48 ~TestUpgradeNotificationListener() override {} |
49 } | |
50 | 49 |
51 const std::vector<int>& notifications_received() const { | 50 const std::vector<int>& notifications_received() const { |
52 return notifications_received_; | 51 return notifications_received_; |
53 } | 52 } |
54 | 53 |
55 private: | 54 private: |
56 // content::NotificationObserver: | 55 // content::NotificationObserver: |
57 virtual void Observe(int type, | 56 void Observe(int type, |
58 const content::NotificationSource& source, | 57 const content::NotificationSource& source, |
59 const content::NotificationDetails& details) override { | 58 const content::NotificationDetails& details) override { |
60 notifications_received_.push_back(type); | 59 notifications_received_.push_back(type); |
61 } | 60 } |
62 | 61 |
63 // Registrar for listening to notifications. | 62 // Registrar for listening to notifications. |
64 content::NotificationRegistrar registrar_; | 63 content::NotificationRegistrar registrar_; |
65 | 64 |
66 // Keeps track of the number and types of notifications that were received. | 65 // Keeps track of the number and types of notifications that were received. |
67 std::vector<int> notifications_received_; | 66 std::vector<int> notifications_received_; |
68 | 67 |
69 DISALLOW_COPY_AND_ASSIGN(TestUpgradeNotificationListener); | 68 DISALLOW_COPY_AND_ASSIGN(TestUpgradeNotificationListener); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 EXPECT_FALSE(detector.notify_upgrade()); | 102 EXPECT_FALSE(detector.notify_upgrade()); |
104 EXPECT_TRUE(notifications_listener.notifications_received().empty()); | 103 EXPECT_TRUE(notifications_listener.notifications_received().empty()); |
105 | 104 |
106 detector.NotifyOnUpgradeWithTimePassed(base::TimeDelta::FromDays(30)); | 105 detector.NotifyOnUpgradeWithTimePassed(base::TimeDelta::FromDays(30)); |
107 EXPECT_TRUE(detector.notify_upgrade()); | 106 EXPECT_TRUE(detector.notify_upgrade()); |
108 ASSERT_EQ(1U, notifications_listener.notifications_received().size()); | 107 ASSERT_EQ(1U, notifications_listener.notifications_received().size()); |
109 EXPECT_EQ(chrome::NOTIFICATION_UPGRADE_RECOMMENDED, | 108 EXPECT_EQ(chrome::NOTIFICATION_UPGRADE_RECOMMENDED, |
110 notifications_listener.notifications_received().front()); | 109 notifications_listener.notifications_received().front()); |
111 EXPECT_EQ(1, detector.trigger_critical_update_call_count()); | 110 EXPECT_EQ(1, detector.trigger_critical_update_call_count()); |
112 } | 111 } |
OLD | NEW |