| 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" |
| 11 #include "platform/testing/TestingPlatformSupport.h" | 11 #include "platform/testing/TestingPlatformSupport.h" |
| 12 #include "platform/testing/URLTestHelpers.h" | 12 #include "platform/testing/URLTestHelpers.h" |
| 13 #include "public/platform/Platform.h" | 13 #include "public/platform/Platform.h" |
| 14 #include "public/platform/WebURL.h" | 14 #include "public/platform/WebURL.h" |
| 15 #include "public/platform/WebURLLoaderMockFactory.h" | 15 #include "public/platform/WebURLLoaderMockFactory.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "third_party/WebKit/Source/platform/weborigin/KURL.h" | 17 #include "third_party/WebKit/Source/platform/weborigin/KURL.h" |
| 18 #include "third_party/skia/include/core/SkBitmap.h" | 18 #include "third_party/skia/include/core/SkBitmap.h" |
| 19 #include "wtf/Functional.h" | 19 #include "wtf/Functional.h" |
| 20 #include "wtf/PtrUtil.h" |
| 20 | 21 |
| 21 namespace blink { | 22 namespace blink { |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 enum class LoadState { kNotLoaded, kLoadFailed, kLoadSuccessful }; | 25 enum class LoadState { kNotLoaded, kLoadFailed, kLoadSuccessful }; |
| 25 | 26 |
| 26 const char kBaseUrl[] = "http://test.com/"; | 27 const char kBaseUrl[] = "http://test.com/"; |
| 27 const char kIcon500x500[] = "500x500.png"; | 28 const char kIcon500x500[] = "500x500.png"; |
| 28 | 29 |
| 29 // This mirrors the definition in NotificationImageLoader.cpp. | 30 // This mirrors the definition in NotificationImageLoader.cpp. |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 EXPECT_EQ(LoadState::kLoadSuccessful, loaded()); | 93 EXPECT_EQ(LoadState::kLoadSuccessful, loaded()); |
| 93 m_histogramTester.expectTotalCount("Notifications.LoadFinishTime.Icon", 1); | 94 m_histogramTester.expectTotalCount("Notifications.LoadFinishTime.Icon", 1); |
| 94 m_histogramTester.expectUniqueSample("Notifications.LoadFileSize.Icon", 7439, | 95 m_histogramTester.expectUniqueSample("Notifications.LoadFileSize.Icon", 7439, |
| 95 1); | 96 1); |
| 96 m_histogramTester.expectTotalCount("Notifications.LoadFailTime.Icon", 0); | 97 m_histogramTester.expectTotalCount("Notifications.LoadFailTime.Icon", 0); |
| 97 } | 98 } |
| 98 | 99 |
| 99 TEST_F(NotificationImageLoaderTest, TimeoutTest) { | 100 TEST_F(NotificationImageLoaderTest, TimeoutTest) { |
| 100 // To test for a timeout, this needs to override the clock in the platform. | 101 // 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. | 102 // Just creating the mock platform will do everything to set it up. |
| 102 TestingPlatformSupportWithMockScheduler testingPlatform; | 103 ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler> |
| 104 testingPlatform( |
| 105 WTF::makeUnique<TestingPlatformSupportWithMockScheduler>()); |
| 103 KURL url = registerMockedURL(kIcon500x500); | 106 KURL url = registerMockedURL(kIcon500x500); |
| 104 loadImage(url); | 107 loadImage(url); |
| 105 | 108 |
| 106 // Run the platform for kImageFetchTimeoutInMs-1 seconds. This should not | 109 // Run the platform for kImageFetchTimeoutInMs-1 seconds. This should not |
| 107 // result in a timeout. | 110 // result in a timeout. |
| 108 testingPlatform.runForPeriodSeconds(kImageFetchTimeoutInMs / 1000 - 1); | 111 testingPlatform->runForPeriodSeconds(kImageFetchTimeoutInMs / 1000 - 1); |
| 109 EXPECT_EQ(LoadState::kNotLoaded, loaded()); | 112 EXPECT_EQ(LoadState::kNotLoaded, loaded()); |
| 110 m_histogramTester.expectTotalCount("Notifications.LoadFinishTime.Icon", 0); | 113 m_histogramTester.expectTotalCount("Notifications.LoadFinishTime.Icon", 0); |
| 111 m_histogramTester.expectTotalCount("Notifications.LoadFileSize.Icon", 0); | 114 m_histogramTester.expectTotalCount("Notifications.LoadFileSize.Icon", 0); |
| 112 m_histogramTester.expectTotalCount("Notifications.LoadFailTime.Icon", 0); | 115 m_histogramTester.expectTotalCount("Notifications.LoadFailTime.Icon", 0); |
| 113 | 116 |
| 114 // Now advance time until a timeout should be expected. | 117 // Now advance time until a timeout should be expected. |
| 115 testingPlatform.runForPeriodSeconds(2); | 118 testingPlatform->runForPeriodSeconds(2); |
| 116 | 119 |
| 117 // If the loader times out, it calls the callback and returns an empty bitmap. | 120 // If the loader times out, it calls the callback and returns an empty bitmap. |
| 118 EXPECT_EQ(LoadState::kLoadFailed, loaded()); | 121 EXPECT_EQ(LoadState::kLoadFailed, loaded()); |
| 119 m_histogramTester.expectTotalCount("Notifications.LoadFinishTime.Icon", 0); | 122 m_histogramTester.expectTotalCount("Notifications.LoadFinishTime.Icon", 0); |
| 120 m_histogramTester.expectTotalCount("Notifications.LoadFileSize.Icon", 0); | 123 m_histogramTester.expectTotalCount("Notifications.LoadFileSize.Icon", 0); |
| 121 // Should log a non-zero failure time. | 124 // Should log a non-zero failure time. |
| 122 m_histogramTester.expectTotalCount("Notifications.LoadFailTime.Icon", 1); | 125 m_histogramTester.expectTotalCount("Notifications.LoadFailTime.Icon", 1); |
| 123 m_histogramTester.expectBucketCount("Notifications.LoadFailTime.Icon", 0, 0); | 126 m_histogramTester.expectBucketCount("Notifications.LoadFailTime.Icon", 0, 0); |
| 124 } | 127 } |
| 125 | 128 |
| 126 } // namspace | 129 } // namspace |
| 127 } // namespace blink | 130 } // namespace blink |
| OLD | NEW |