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

Unified Diff: chrome/browser/extensions/updater/extension_updater_unittest.cc

Issue 279453002: Support multiple sign-in for extension updates. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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
Index: chrome/browser/extensions/updater/extension_updater_unittest.cc
diff --git a/chrome/browser/extensions/updater/extension_updater_unittest.cc b/chrome/browser/extensions/updater/extension_updater_unittest.cc
index 6c3721ce1b920024fd926a0cac81550f9c2fe15d..32e04905b3f7c93823c0e287ecde605273ae8c42 100644
--- a/chrome/browser/extensions/updater/extension_updater_unittest.cc
+++ b/chrome/browser/extensions/updater/extension_updater_unittest.cc
@@ -60,6 +60,7 @@
#include "net/url_request/url_request_status.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "url/third_party/mozilla/url_parse.h"
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/login/user_manager.h"
@@ -113,6 +114,8 @@ const net::BackoffEntry::Policy kNoBackoffPolicy = {
const char kEmptyUpdateUrlData[] = "";
+const char kAuthUserQueryKey[] = "authuser";
+
int kExpectedLoadFlags =
net::LOAD_DO_NOT_SEND_COOKIES |
net::LOAD_DO_NOT_SAVE_COOKIES |
@@ -248,6 +251,25 @@ class NotificationsObserver : public content::NotificationObserver {
DISALLOW_COPY_AND_ASSIGN(NotificationsObserver);
};
+// Extracts the integer value of the |authuser| query parameter. Returns 0 if
+// the parameter is not set.
+int GetAuthUserQueryValue(const GURL& url) {
+ std::string query_string = url.query();
+ url::Component query(0, query_string.length());
+ url::Component key, value;
+ while (url::ExtractQueryKeyValue(
+ query_string.c_str(), &query, &key, &value)) {
+ std::string key_string = query_string.substr(key.begin, key.len);
+ if (key_string == kAuthUserQueryKey) {
+ int user_index = 0;
+ base::StringToInt(query_string.substr(value.begin, value.len),
+ &user_index);
+ return user_index;
+ }
+ }
+ return 0;
+}
+
} // namespace
// Base class for further specialized test classes.
@@ -1082,7 +1104,11 @@ class ExtensionUpdaterTest : public testing::Test {
// Update a single extension in an environment where the download request
// initially responds with a 403 status. Expect the fetcher to automatically
// retry with cookies enabled.
- void TestSingleProtectedExtensionDownloading(bool use_https, bool fail) {
+ void TestSingleProtectedExtensionDownloading(
+ bool use_https,
+ bool fail,
+ int max_authuser,
+ int valid_authuser) {
net::TestURLFetcherFactory factory;
net::TestURLFetcher* fetcher = NULL;
scoped_ptr<ServiceForDownloadTests> service(
@@ -1135,16 +1161,40 @@ class ExtensionUpdaterTest : public testing::Test {
}
// Attempt to fetch again after the auth failure.
+ bool succeed = !fail;
if (fail) {
- // Fail and verify that the fetch queue is cleared.
- fetcher->set_url(test_url);
- fetcher->set_status(net::URLRequestStatus());
- fetcher->set_response_code(403);
- fetcher->delegate()->OnURLFetchComplete(fetcher);
- RunUntilIdle();
- EXPECT_EQ(0U, updater.downloader_->extensions_queue_.active_request());
- } else {
- // Succeed
+ // Do not simulate incremental authuser retries.
+ if (max_authuser == 0) {
+ // Fail and verify that the fetch queue is cleared.
+ fetcher->set_url(test_url);
+ fetcher->set_status(net::URLRequestStatus());
+ fetcher->set_response_code(401);
+ fetcher->delegate()->OnURLFetchComplete(fetcher);
+ RunUntilIdle();
+
+ EXPECT_EQ(0U, updater.downloader_->extensions_queue_.active_request());
+ return;
+ }
+
+ // Simulate incremental authuser retries.
+ for (int user_index = 0; user_index <= max_authuser; ++user_index) {
+ const ExtensionDownloader::ExtensionFetch& fetch =
+ *updater.downloader_->extensions_queue_.active_request();
+ EXPECT_EQ(user_index, GetAuthUserQueryValue(fetch.url));
+ if (user_index == valid_authuser) {
+ succeed = true;
+ break;
+ }
+ fetcher->set_url(fetch.url);
+ fetcher->set_status(net::URLRequestStatus());
+ fetcher->set_response_code(403);
+ fetcher->delegate()->OnURLFetchComplete(fetcher);
+ RunUntilIdle();
+ }
+ }
+
+ // Succeed
+ if (succeed) {
base::FilePath extension_file_path(FILE_PATH_LITERAL("/whatever"));
fetcher->set_url(test_url);
fetcher->set_status(net::URLRequestStatus());
@@ -1586,15 +1636,27 @@ TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloadingFailurePending) {
}
TEST_F(ExtensionUpdaterTest, TestSingleProtectedExtensionDownloading) {
- TestSingleProtectedExtensionDownloading(true, false);
+ TestSingleProtectedExtensionDownloading(true, false, 0, 0);
}
TEST_F(ExtensionUpdaterTest, TestSingleProtectedExtensionDownloadingFailure) {
- TestSingleProtectedExtensionDownloading(true, true);
+ TestSingleProtectedExtensionDownloading(true, true, 0, 0);
}
TEST_F(ExtensionUpdaterTest, TestSingleProtectedExtensionDownloadingNoHTTPS) {
- TestSingleProtectedExtensionDownloading(false, false);
+ TestSingleProtectedExtensionDownloading(false, false, 0, 0);
+}
+
+TEST_F(ExtensionUpdaterTest, TestSingleProtectedExtensionDownloadingWithNonDefaultAuthUser1) {
asargent_no_longer_on_chrome 2014/05/08 04:27:11 nit: Can probably omit the prefix "Test" from the
Ken Rockot(use gerrit already) 2014/05/08 05:23:09 Done.
+ TestSingleProtectedExtensionDownloading(true, true, 2, 1);
+}
+
+TEST_F(ExtensionUpdaterTest, TestSingleProtectedExtensionDownloadingWithNonDefaultAuthUser2) {
+ TestSingleProtectedExtensionDownloading(true, true, 2, 2);
+}
+
+TEST_F(ExtensionUpdaterTest, TestSingleProtectedExtensionDownloadingAuthUserExhaustionFailure) {
+ TestSingleProtectedExtensionDownloading(true, true, 2, 5);
}
TEST_F(ExtensionUpdaterTest, TestMultipleExtensionDownloadingUpdatesFail) {

Powered by Google App Engine
This is Rietveld 408576698