OLD | NEW |
1 // Copyright 2016 Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "modules/notifications/NotificationImageLoader.h" | 5 #include "modules/notifications/NotificationImageLoader.h" |
6 | 6 |
7 #include "core/dom/ExecutionContext.h" | 7 #include "core/dom/ExecutionContext.h" |
8 #include "core/fetch/MemoryCache.h" | 8 #include "core/fetch/MemoryCache.h" |
9 #include "core/testing/DummyPageHolder.h" | 9 #include "core/testing/DummyPageHolder.h" |
10 #include "platform/testing/HistogramTester.h" | 10 #include "platform/testing/HistogramTester.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 EXPECT_EQ(LoadState::kLoadSuccessful, loaded()); | 92 EXPECT_EQ(LoadState::kLoadSuccessful, loaded()); |
93 m_histogramTester.expectTotalCount("Notifications.LoadFinishTime.Icon", 1); | 93 m_histogramTester.expectTotalCount("Notifications.LoadFinishTime.Icon", 1); |
94 m_histogramTester.expectUniqueSample("Notifications.LoadFileSize.Icon", 7439, | 94 m_histogramTester.expectUniqueSample("Notifications.LoadFileSize.Icon", 7439, |
95 1); | 95 1); |
96 m_histogramTester.expectTotalCount("Notifications.LoadFailTime.Icon", 0); | 96 m_histogramTester.expectTotalCount("Notifications.LoadFailTime.Icon", 0); |
97 } | 97 } |
98 | 98 |
99 TEST_F(NotificationImageLoaderTest, TimeoutTest) { | 99 TEST_F(NotificationImageLoaderTest, TimeoutTest) { |
100 // To test for a timeout, this needs to override the clock in the platform. | 100 // To test for a timeout, this needs to override the clock in the platform. |
101 // Just creating the mock platform will do everything to set it up. | 101 // Just creating the mock platform will do everything to set it up. |
102 TestingPlatformSupportWithMockScheduler testingPlatform; | 102 ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler> |
| 103 testingPlatform(new TestingPlatformSupportWithMockScheduler); |
103 KURL url = registerMockedURL(kIcon500x500); | 104 KURL url = registerMockedURL(kIcon500x500); |
104 loadImage(url); | 105 loadImage(url); |
105 | 106 |
106 // Run the platform for kImageFetchTimeoutInMs-1 seconds. This should not | 107 // Run the platform for kImageFetchTimeoutInMs-1 seconds. This should not |
107 // result in a timeout. | 108 // result in a timeout. |
108 testingPlatform.runForPeriodSeconds(kImageFetchTimeoutInMs / 1000 - 1); | 109 testingPlatform->runForPeriodSeconds(kImageFetchTimeoutInMs / 1000 - 1); |
109 EXPECT_EQ(LoadState::kNotLoaded, loaded()); | 110 EXPECT_EQ(LoadState::kNotLoaded, loaded()); |
110 m_histogramTester.expectTotalCount("Notifications.LoadFinishTime.Icon", 0); | 111 m_histogramTester.expectTotalCount("Notifications.LoadFinishTime.Icon", 0); |
111 m_histogramTester.expectTotalCount("Notifications.LoadFileSize.Icon", 0); | 112 m_histogramTester.expectTotalCount("Notifications.LoadFileSize.Icon", 0); |
112 m_histogramTester.expectTotalCount("Notifications.LoadFailTime.Icon", 0); | 113 m_histogramTester.expectTotalCount("Notifications.LoadFailTime.Icon", 0); |
113 | 114 |
114 // Now advance time until a timeout should be expected. | 115 // Now advance time until a timeout should be expected. |
115 testingPlatform.runForPeriodSeconds(2); | 116 testingPlatform->runForPeriodSeconds(2); |
116 | 117 |
117 // If the loader times out, it calls the callback and returns an empty bitmap. | 118 // If the loader times out, it calls the callback and returns an empty bitmap. |
118 EXPECT_EQ(LoadState::kLoadFailed, loaded()); | 119 EXPECT_EQ(LoadState::kLoadFailed, loaded()); |
119 m_histogramTester.expectTotalCount("Notifications.LoadFinishTime.Icon", 0); | 120 m_histogramTester.expectTotalCount("Notifications.LoadFinishTime.Icon", 0); |
120 m_histogramTester.expectTotalCount("Notifications.LoadFileSize.Icon", 0); | 121 m_histogramTester.expectTotalCount("Notifications.LoadFileSize.Icon", 0); |
121 // Should log a non-zero failure time. | 122 // Should log a non-zero failure time. |
122 m_histogramTester.expectTotalCount("Notifications.LoadFailTime.Icon", 1); | 123 m_histogramTester.expectTotalCount("Notifications.LoadFailTime.Icon", 1); |
123 m_histogramTester.expectBucketCount("Notifications.LoadFailTime.Icon", 0, 0); | 124 m_histogramTester.expectBucketCount("Notifications.LoadFailTime.Icon", 0, 0); |
124 } | 125 } |
125 | 126 |
126 } // namspace | 127 } // namspace |
127 } // namespace blink | 128 } // namespace blink |
OLD | NEW |