Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(490)

Side by Side Diff: third_party/WebKit/Source/modules/notifications/NotificationImageLoaderTest.cpp

Issue 2588403002: TestingPlatformSupport: register Platform instance correctly (Closed)
Patch Set: review #32 Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 m_histogramTester.expectTotalCount("Notifications.LoadFailTime.Icon", 0); 90 m_histogramTester.expectTotalCount("Notifications.LoadFailTime.Icon", 0);
91 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); 91 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
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 ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
101 platform;
102
100 // To test for a timeout, this needs to override the clock in the platform. 103 // 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. 104 // Just creating the mock platform will do everything to set it up.
102 TestingPlatformSupportWithMockScheduler testingPlatform;
103 KURL url = registerMockedURL(kIcon500x500); 105 KURL url = registerMockedURL(kIcon500x500);
104 loadImage(url); 106 loadImage(url);
105 107
106 // Run the platform for kImageFetchTimeoutInMs-1 seconds. This should not 108 // Run the platform for kImageFetchTimeoutInMs-1 seconds. This should not
107 // result in a timeout. 109 // result in a timeout.
108 testingPlatform.runForPeriodSeconds(kImageFetchTimeoutInMs / 1000 - 1); 110 platform->runForPeriodSeconds(kImageFetchTimeoutInMs / 1000 - 1);
109 EXPECT_EQ(LoadState::kNotLoaded, loaded()); 111 EXPECT_EQ(LoadState::kNotLoaded, loaded());
110 m_histogramTester.expectTotalCount("Notifications.LoadFinishTime.Icon", 0); 112 m_histogramTester.expectTotalCount("Notifications.LoadFinishTime.Icon", 0);
111 m_histogramTester.expectTotalCount("Notifications.LoadFileSize.Icon", 0); 113 m_histogramTester.expectTotalCount("Notifications.LoadFileSize.Icon", 0);
112 m_histogramTester.expectTotalCount("Notifications.LoadFailTime.Icon", 0); 114 m_histogramTester.expectTotalCount("Notifications.LoadFailTime.Icon", 0);
113 115
114 // Now advance time until a timeout should be expected. 116 // Now advance time until a timeout should be expected.
115 testingPlatform.runForPeriodSeconds(2); 117 platform->runForPeriodSeconds(2);
116 118
117 // If the loader times out, it calls the callback and returns an empty bitmap. 119 // If the loader times out, it calls the callback and returns an empty bitmap.
118 EXPECT_EQ(LoadState::kLoadFailed, loaded()); 120 EXPECT_EQ(LoadState::kLoadFailed, loaded());
119 m_histogramTester.expectTotalCount("Notifications.LoadFinishTime.Icon", 0); 121 m_histogramTester.expectTotalCount("Notifications.LoadFinishTime.Icon", 0);
120 m_histogramTester.expectTotalCount("Notifications.LoadFileSize.Icon", 0); 122 m_histogramTester.expectTotalCount("Notifications.LoadFileSize.Icon", 0);
121 // Should log a non-zero failure time. 123 // Should log a non-zero failure time.
122 m_histogramTester.expectTotalCount("Notifications.LoadFailTime.Icon", 1); 124 m_histogramTester.expectTotalCount("Notifications.LoadFailTime.Icon", 1);
123 m_histogramTester.expectBucketCount("Notifications.LoadFailTime.Icon", 0, 0); 125 m_histogramTester.expectBucketCount("Notifications.LoadFailTime.Icon", 0, 0);
124 } 126 }
125 127
126 } // namspace 128 } // namspace
127 } // namespace blink 129 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698