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

Unified Diff: chrome/browser/download/download_query_unittest.cc

Issue 1706193002: Expose final download URL (actual url after redirects) in the extension API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/download/download_query.cc ('k') | chrome/browser/extensions/api/downloads/downloads_api.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/download/download_query_unittest.cc
diff --git a/chrome/browser/download/download_query_unittest.cc b/chrome/browser/download/download_query_unittest.cc
index 78046ecae989672ff83b76efc74543ade62ce093..09ceabf54a64b85205a40ffbbb326e7289fdd2e1 100644
--- a/chrome/browser/download/download_query_unittest.cc
+++ b/chrome/browser/download/download_query_unittest.cc
@@ -204,13 +204,15 @@ TEST_F(DownloadQueryTest, DownloadQueryTest_FilterGenericQueryFilename) {
GURL fail_url("http://example.com/fail");
EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url));
EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url));
+ EXPECT_CALL(mock(0), GetURL()).WillRepeatedly(ReturnRef(fail_url));
+ EXPECT_CALL(mock(1), GetURL()).WillRepeatedly(ReturnRef(fail_url));
std::vector<std::string> query_terms;
query_terms.push_back("query");
AddFilter(DownloadQuery::FILTER_QUERY, query_terms);
ExpectStandardFilterResults();
}
-TEST_F(DownloadQueryTest, DownloadQueryTest_FilterGenericQueryUrl) {
+TEST_F(DownloadQueryTest, DownloadQueryTest_FilterGenericQueryOriginalUrl) {
CreateMocks(2);
EXPECT_CALL(mock(0), GetBrowserContext()).WillRepeatedly(Return(
static_cast<content::BrowserContext*>(NULL)));
@@ -225,6 +227,78 @@ TEST_F(DownloadQueryTest, DownloadQueryTest_FilterGenericQueryUrl) {
EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(match_url));
GURL fail_url("http://example.com/fail");
EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url));
+ EXPECT_CALL(mock(0), GetURL()).WillRepeatedly(ReturnRef(fail_url));
+ EXPECT_CALL(mock(1), GetURL()).WillRepeatedly(ReturnRef(fail_url));
+ std::vector<std::string> query_terms;
+ query_terms.push_back("query");
+ AddFilter(DownloadQuery::FILTER_QUERY, query_terms);
+ ExpectStandardFilterResults();
+}
+
+TEST_F(DownloadQueryTest,
+ DownloadQueryTest_FilterGenericQueryOriginalUrlUnescaping) {
+ CreateMocks(2);
+ EXPECT_CALL(mock(0), GetBrowserContext()).WillRepeatedly(Return(
+ static_cast<content::BrowserContext*>(NULL)));
+ EXPECT_CALL(mock(1), GetBrowserContext()).WillRepeatedly(Return(
+ static_cast<content::BrowserContext*>(NULL)));
+ base::FilePath fail_filename(FILE_PATH_LITERAL("fail"));
+ EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef(
+ fail_filename));
+ EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef(
+ fail_filename));
+ GURL match_url("http://q%75%65%72y.c%6Fm/%71uer%79");
+ GURL fail_url("http://%65xampl%65.com/%66ai%6C");
+ EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(match_url));
+ EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url));
+ EXPECT_CALL(mock(0), GetURL()).WillRepeatedly(ReturnRef(fail_url));
+ EXPECT_CALL(mock(1), GetURL()).WillRepeatedly(ReturnRef(fail_url));
+ std::vector<std::string> query_terms;
+ query_terms.push_back("query");
+ AddFilter(DownloadQuery::FILTER_QUERY, query_terms);
+ ExpectStandardFilterResults();
+}
+
+TEST_F(DownloadQueryTest, DownloadQueryTest_FilterGenericQueryUrl) {
+ CreateMocks(2);
+ EXPECT_CALL(mock(0), GetBrowserContext()).WillRepeatedly(Return(
+ static_cast<content::BrowserContext*>(NULL)));
+ EXPECT_CALL(mock(1), GetBrowserContext()).WillRepeatedly(Return(
+ static_cast<content::BrowserContext*>(NULL)));
+ base::FilePath fail_filename(FILE_PATH_LITERAL("fail"));
+ EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef(
+ fail_filename));
+ EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef(
+ fail_filename));
+ GURL match_url("http://query.com/query");
+ GURL fail_url("http://example.com/fail");
+ EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url));
+ EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url));
+ EXPECT_CALL(mock(0), GetURL()).WillRepeatedly(ReturnRef(match_url));
+ EXPECT_CALL(mock(1), GetURL()).WillRepeatedly(ReturnRef(fail_url));
+ std::vector<std::string> query_terms;
+ query_terms.push_back("query");
+ AddFilter(DownloadQuery::FILTER_QUERY, query_terms);
+ ExpectStandardFilterResults();
+}
+
+TEST_F(DownloadQueryTest, DownloadQueryTest_FilterGenericQueryUrlUnescaping) {
+ CreateMocks(2);
+ EXPECT_CALL(mock(0), GetBrowserContext()).WillRepeatedly(Return(
+ static_cast<content::BrowserContext*>(NULL)));
+ EXPECT_CALL(mock(1), GetBrowserContext()).WillRepeatedly(Return(
+ static_cast<content::BrowserContext*>(NULL)));
+ base::FilePath fail_filename(FILE_PATH_LITERAL("fail"));
+ EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef(
+ fail_filename));
+ EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef(
+ fail_filename));
+ GURL match_url("http://%71uer%79.com/qu%65ry");
+ GURL fail_url("http://e%78am%70le.com/f%61il");
+ EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url));
+ EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url));
+ EXPECT_CALL(mock(0), GetURL()).WillRepeatedly(ReturnRef(match_url));
+ EXPECT_CALL(mock(1), GetURL()).WillRepeatedly(ReturnRef(fail_url));
std::vector<std::string> query_terms;
query_terms.push_back("query");
AddFilter(DownloadQuery::FILTER_QUERY, query_terms);
@@ -253,6 +327,8 @@ TEST_F(DownloadQueryTest, DownloadQueryTest_FilterGenericQueryFilenameI18N) {
GURL fail_url("http://example.com/fail");
EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url));
EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url));
+ EXPECT_CALL(mock(0), GetURL()).WillRepeatedly(ReturnRef(fail_url));
+ EXPECT_CALL(mock(1), GetURL()).WillRepeatedly(ReturnRef(fail_url));
std::vector<base::FilePath::StringType> query_terms;
query_terms.push_back(kTestString);
AddFilter(DownloadQuery::FILTER_QUERY, query_terms);
@@ -295,32 +371,63 @@ TEST_F(DownloadQueryTest, DownloadQueryTest_FilterFilename) {
ExpectStandardFilterResults();
}
-TEST_F(DownloadQueryTest, DownloadQueryTest_FilterUrlRegex) {
+TEST_F(DownloadQueryTest, DownloadQueryTest_FilterOriginalUrlRegex) {
CreateMocks(2);
GURL match_url("http://query.com/query");
EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(match_url));
GURL fail_url("http://example.com/fail");
EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url));
- AddFilter(DownloadQuery::FILTER_URL_REGEX, "query");
+ AddFilter(DownloadQuery::FILTER_ORIGINAL_URL_REGEX, "query");
ExpectStandardFilterResults();
}
-TEST_F(DownloadQueryTest, DownloadQueryTest_SortUrl) {
+TEST_F(DownloadQueryTest, DownloadQueryTest_SortOriginalUrl) {
CreateMocks(2);
GURL b_url("http://example.com/b");
EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(b_url));
GURL a_url("http://example.com/a");
EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(a_url));
- query()->AddSorter(DownloadQuery::SORT_URL, DownloadQuery::ASCENDING);
+ query()->AddSorter(
+ DownloadQuery::SORT_ORIGINAL_URL, DownloadQuery::ASCENDING);
ExpectSortInverted();
}
-TEST_F(DownloadQueryTest, DownloadQueryTest_FilterUrl) {
+TEST_F(DownloadQueryTest, DownloadQueryTest_FilterOriginalUrl) {
CreateMocks(2);
GURL match_url("http://query.com/query");
EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(match_url));
GURL fail_url("http://example.com/fail");
EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url));
+ AddFilter(DownloadQuery::FILTER_ORIGINAL_URL, match_url.spec().c_str());
+ ExpectStandardFilterResults();
+}
+
+TEST_F(DownloadQueryTest, DownloadQueryTest_FilterUrlRegex) {
+ CreateMocks(2);
+ GURL match_url("http://query.com/query");
+ EXPECT_CALL(mock(0), GetURL()).WillRepeatedly(ReturnRef(match_url));
+ GURL fail_url("http://example.com/fail");
+ EXPECT_CALL(mock(1), GetURL()).WillRepeatedly(ReturnRef(fail_url));
+ AddFilter(DownloadQuery::FILTER_URL_REGEX, "query");
+ ExpectStandardFilterResults();
+}
+
+TEST_F(DownloadQueryTest, DownloadQueryTest_SortUrl) {
+ CreateMocks(2);
+ GURL b_url("http://example.com/b");
+ EXPECT_CALL(mock(0), GetURL()).WillRepeatedly(ReturnRef(b_url));
+ GURL a_url("http://example.com/a");
+ EXPECT_CALL(mock(1), GetURL()).WillRepeatedly(ReturnRef(a_url));
+ query()->AddSorter(DownloadQuery::SORT_URL, DownloadQuery::ASCENDING);
+ ExpectSortInverted();
+}
+
+TEST_F(DownloadQueryTest, DownloadQueryTest_FilterUrl) {
+ CreateMocks(2);
+ GURL match_url("http://query.com/query");
+ EXPECT_CALL(mock(0), GetURL()).WillRepeatedly(ReturnRef(match_url));
+ GURL fail_url("http://example.com/fail");
+ EXPECT_CALL(mock(1), GetURL()).WillRepeatedly(ReturnRef(fail_url));
AddFilter(DownloadQuery::FILTER_URL, match_url.spec().c_str());
ExpectStandardFilterResults();
}
« no previous file with comments | « chrome/browser/download/download_query.cc ('k') | chrome/browser/extensions/api/downloads/downloads_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698