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

Side by Side Diff: chrome/browser/extensions/api/downloads/downloads_api_unittest.cc

Issue 2956213003: Statically allocate extension download lookups. (Closed)
Patch Set: Better tests Created 3 years, 5 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
« no previous file with comments | « chrome/browser/extensions/api/downloads/downloads_api.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "chrome/browser/extensions/api/downloads/downloads_api.h" 5 #include "chrome/browser/extensions/api/downloads/downloads_api.h"
6 6
7 #include <algorithm>
8
7 #include "base/macros.h" 9 #include "base/macros.h"
8 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
9 #include "chrome/browser/download/download_core_service_factory.h" 11 #include "chrome/browser/download/download_core_service_factory.h"
10 #include "chrome/browser/download/download_core_service_impl.h" 12 #include "chrome/browser/download/download_core_service_impl.h"
11 #include "chrome/browser/download/download_history.h" 13 #include "chrome/browser/download/download_history.h"
12 #include "chrome/browser/extensions/extension_api_unittest.h" 14 #include "chrome/browser/extensions/extension_api_unittest.h"
13 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
14 #include "content/public/test/mock_download_manager.h" 16 #include "content/public/test/mock_download_manager.h"
15 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 Profile::FromBrowserContext(browser_context)); 122 Profile::FromBrowserContext(browser_context));
121 } 123 }
122 124
123 // Tests that Number/double properties in query are parsed correctly. 125 // Tests that Number/double properties in query are parsed correctly.
124 // Regression test for https://crbug.com/617435. 126 // Regression test for https://crbug.com/617435.
125 TEST_F(DownloadsApiUnitTest, ParseSearchQuery) { 127 TEST_F(DownloadsApiUnitTest, ParseSearchQuery) {
126 RunFunction(new DownloadsSearchFunction, "[{\"totalBytesLess\":1}]"); 128 RunFunction(new DownloadsSearchFunction, "[{\"totalBytesLess\":1}]");
127 RunFunction(new DownloadsSearchFunction, "[{\"totalBytesGreater\":2}]"); 129 RunFunction(new DownloadsSearchFunction, "[{\"totalBytesGreater\":2}]");
128 } 130 }
129 131
132 // Marked as an "internal" unit test because it doesn't use the TEST_F macro so
133 // the name must be different.
134 TEST(DownloadsApiInternalUnitTest, FilterTypeSorted) {
135 struct KeyCompare {
136 bool operator()(const DownloadQueryFilterTypePair& a,
137 const DownloadQueryFilterTypePair& b) const {
138 return strcmp(a.first, b.first) < 0;
139 }
140 };
141 EXPECT_TRUE(std::is_sorted(DownloadQueryFilterTypeBeginForTest(),
142 DownloadQueryFilterTypeEndForTest(),
143 KeyCompare()));
144
145 // All items should be found.
146 for (const DownloadQueryFilterTypePair* cur =
147 DownloadQueryFilterTypeBeginForTest();
148 cur != DownloadQueryFilterTypeEndForTest(); ++cur) {
149 EXPECT_EQ(cur, FindDownloadFilterTypeByString(cur->first));
150 }
151
152 EXPECT_EQ(nullptr, FindDownloadFilterTypeByString("NOTFOUND"));
153 }
154
155 // Marked as an "internal" unit test because it doesn't use the TEST_F macro so
156 // the name must be different.
157 TEST(DownloadsApiInternalUnitTest, SortTypeSorted) {
158 struct KeyCompare {
159 bool operator()(const DownloadQuerySortTypePair& a,
160 const DownloadQuerySortTypePair& b) const {
161 return strcmp(a.first, b.first) < 0;
162 }
163 };
164 EXPECT_TRUE(std::is_sorted(DownloadQuerySortTypeBeginForTest(),
165 DownloadQuerySortTypeEndForTest(), KeyCompare()));
166
167 // All items should be found.
168 for (const DownloadQuerySortTypePair* cur =
169 DownloadQuerySortTypeBeginForTest();
170 cur != DownloadQuerySortTypeEndForTest(); ++cur) {
171 EXPECT_EQ(cur, FindDownloadSortTypeByString(cur->first));
172 }
173
174 EXPECT_EQ(nullptr, FindDownloadSortTypeByString("NOTFOUND"));
175 }
176
130 } // namespace extensions 177 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/downloads/downloads_api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698