OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "modules/notifications/NotificationResourcesLoader.h" | 5 #include "modules/notifications/NotificationResourcesLoader.h" |
6 | 6 |
| 7 #include <memory> |
7 #include "core/testing/DummyPageHolder.h" | 8 #include "core/testing/DummyPageHolder.h" |
8 #include "platform/heap/Heap.h" | 9 #include "platform/heap/Heap.h" |
9 #include "platform/loader/fetch/MemoryCache.h" | 10 #include "platform/loader/fetch/MemoryCache.h" |
10 #include "platform/testing/URLTestHelpers.h" | 11 #include "platform/testing/URLTestHelpers.h" |
| 12 #include "platform/testing/UnitTestHelpers.h" |
11 #include "platform/weborigin/KURL.h" | 13 #include "platform/weborigin/KURL.h" |
12 #include "public/platform/Platform.h" | 14 #include "public/platform/Platform.h" |
13 #include "public/platform/WebURL.h" | 15 #include "public/platform/WebURL.h" |
14 #include "public/platform/WebURLLoaderMockFactory.h" | 16 #include "public/platform/WebURLLoaderMockFactory.h" |
15 #include "public/platform/WebURLResponse.h" | 17 #include "public/platform/WebURLResponse.h" |
16 #include "public/platform/modules/notifications/WebNotificationConstants.h" | 18 #include "public/platform/modules/notifications/WebNotificationConstants.h" |
17 #include "public/platform/modules/notifications/WebNotificationData.h" | 19 #include "public/platform/modules/notifications/WebNotificationData.h" |
18 #include "public/platform/modules/notifications/WebNotificationResources.h" | 20 #include "public/platform/modules/notifications/WebNotificationResources.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
20 #include "wtf/Functional.h" | 22 #include "wtf/Functional.h" |
21 #include "wtf/text/WTFString.h" | 23 #include "wtf/text/WTFString.h" |
22 #include <memory> | |
23 | 24 |
24 namespace blink { | 25 namespace blink { |
25 namespace { | 26 namespace { |
26 | 27 |
27 const char kBaseUrl[] = "http://test.com/"; | 28 constexpr char kBaseUrl[] = "http://test.com/"; |
28 const char kIcon48x48[] = "48x48.png"; | 29 constexpr char kBaseDir[] = "notifications/"; |
29 const char kIcon100x100[] = "100x100.png"; | 30 constexpr char kIcon48x48[] = "48x48.png"; |
30 const char kIcon110x110[] = "110x110.png"; | 31 constexpr char kIcon100x100[] = "100x100.png"; |
31 const char kIcon120x120[] = "120x120.png"; | 32 constexpr char kIcon110x110[] = "110x110.png"; |
32 const char kIcon500x500[] = "500x500.png"; | 33 constexpr char kIcon120x120[] = "120x120.png"; |
33 const char kIcon3000x1000[] = "3000x1000.png"; | 34 constexpr char kIcon500x500[] = "500x500.png"; |
34 const char kIcon3000x2000[] = "3000x2000.png"; | 35 constexpr char kIcon3000x1000[] = "3000x1000.png"; |
| 36 constexpr char kIcon3000x2000[] = "3000x2000.png"; |
35 | 37 |
36 class NotificationResourcesLoaderTest : public ::testing::Test { | 38 class NotificationResourcesLoaderTest : public ::testing::Test { |
37 public: | 39 public: |
38 NotificationResourcesLoaderTest() | 40 NotificationResourcesLoaderTest() |
39 : m_page(DummyPageHolder::create()), | 41 : m_page(DummyPageHolder::create()), |
40 m_loader(new NotificationResourcesLoader( | 42 m_loader(new NotificationResourcesLoader( |
41 bind(&NotificationResourcesLoaderTest::didFetchResources, | 43 bind(&NotificationResourcesLoaderTest::didFetchResources, |
42 WTF::unretained(this)))) {} | 44 WTF::unretained(this)))) {} |
43 | 45 |
44 ~NotificationResourcesLoaderTest() override { | 46 ~NotificationResourcesLoaderTest() override { |
45 m_loader->stop(); | 47 m_loader->stop(); |
46 Platform::current()->getURLLoaderMockFactory()->unregisterAllURLs(); | 48 Platform::current()->getURLLoaderMockFactory()->unregisterAllURLs(); |
47 memoryCache()->evictResources(); | 49 memoryCache()->evictResources(); |
48 } | 50 } |
49 | 51 |
50 protected: | 52 protected: |
51 ExecutionContext* executionContext() const { return &m_page->document(); } | 53 ExecutionContext* executionContext() const { return &m_page->document(); } |
52 | 54 |
53 NotificationResourcesLoader* loader() const { return m_loader.get(); } | 55 NotificationResourcesLoader* loader() const { return m_loader.get(); } |
54 | 56 |
55 WebNotificationResources* resources() const { return m_resources.get(); } | 57 WebNotificationResources* resources() const { return m_resources.get(); } |
56 | 58 |
57 void didFetchResources(NotificationResourcesLoader* loader) { | 59 void didFetchResources(NotificationResourcesLoader* loader) { |
58 m_resources = loader->getResources(); | 60 m_resources = loader->getResources(); |
59 } | 61 } |
60 | 62 |
61 // Registers a mocked url. When fetched, |fileName| will be loaded from the | 63 // Registers a mocked url. When fetched, |fileName| will be loaded from the |
62 // test data directory. | 64 // test data directory. |
63 WebURL registerMockedURL(const String& fileName) { | 65 WebURL registerMockedURL(const String& fileName) { |
64 WebURL url(KURL(ParsedURLString, kBaseUrl + fileName)); | 66 WebURL registeredUrl = URLTestHelpers::registerMockedURLLoadFromBase( |
65 | 67 kBaseUrl, testing::webTestDataPath(kBaseDir), fileName, "image/png"); |
66 URLTestHelpers::registerMockedURLLoad(url, fileName, "notifications/", | 68 return registeredUrl; |
67 "image/png"); | |
68 | |
69 return url; | |
70 } | 69 } |
71 | 70 |
72 // Registers a mocked url that will fail to be fetched, with a 404 error. | 71 // Registers a mocked url that will fail to be fetched, with a 404 error. |
73 WebURL registerMockedErrorURL(const String& fileName) { | 72 WebURL registerMockedErrorURL(const String& fileName) { |
74 WebURL url(KURL(ParsedURLString, kBaseUrl + fileName)); | 73 WebURL url(KURL(ParsedURLString, kBaseUrl + fileName)); |
75 URLTestHelpers::registerMockedErrorURLLoad(url); | 74 URLTestHelpers::registerMockedErrorURLLoad(url); |
76 return url; | 75 return url; |
77 } | 76 } |
78 | 77 |
79 private: | 78 private: |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); | 265 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); |
267 | 266 |
268 // Loading should have been cancelled when |stop| was called so no resources | 267 // Loading should have been cancelled when |stop| was called so no resources |
269 // should have been received by the test even though | 268 // should have been received by the test even though |
270 // |serveAsynchronousRequests| was called. | 269 // |serveAsynchronousRequests| was called. |
271 ASSERT_FALSE(resources()); | 270 ASSERT_FALSE(resources()); |
272 } | 271 } |
273 | 272 |
274 } // namespace | 273 } // namespace |
275 } // namespace blink | 274 } // namespace blink |
OLD | NEW |