summaryrefslogtreecommitdiffstats
path: root/google_apis
diff options
context:
space:
mode:
authorzelidrag@chromium.org <zelidrag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-08 07:09:28 +0000
committerzelidrag@chromium.org <zelidrag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-08 07:09:28 +0000
commitb16c5d87d5cb06f5e1d40f845fb805daba24f8f7 (patch)
tree284bc449025321933b9ac31e604470bc9aa4830d /google_apis
parentfefa1666597f12a7911caf93bf8983e83ba39c80 (diff)
downloadchromium_src-b16c5d87d5cb06f5e1d40f845fb805daba24f8f7.zip
chromium_src-b16c5d87d5cb06f5e1d40f845fb805daba24f8f7.tar.gz
chromium_src-b16c5d87d5cb06f5e1d40f845fb805daba24f8f7.tar.bz2
Added secondary /MergeSession verification step.
We will now inspect outcome of /ListAccounts call to check if the primary session SID/LSID cookies got run over by browser session restore process. For now, the outcome of this test is just reported as a UMA histogram. BUG=309131 TEST=none Review URL: https://codereview.chromium.org/103463003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@239385 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'google_apis')
-rw-r--r--google_apis/gaia/gaia_auth_util.cc36
-rw-r--r--google_apis/gaia/gaia_auth_util.h5
-rw-r--r--google_apis/gaia/gaia_auth_util_unittest.cc34
3 files changed, 73 insertions, 2 deletions
diff --git a/google_apis/gaia/gaia_auth_util.cc b/google_apis/gaia/gaia_auth_util.cc
index ca2d66e..f8f95c1 100644
--- a/google_apis/gaia/gaia_auth_util.cc
+++ b/google_apis/gaia/gaia_auth_util.cc
@@ -4,11 +4,11 @@
#include "google_apis/gaia/gaia_auth_util.h"
-#include <vector>
-
+#include "base/json/json_reader.h"
#include "base/logging.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
+#include "base/values.h"
#include "google_apis/gaia/gaia_urls.h"
#include "url/gurl.h"
@@ -72,4 +72,36 @@ bool IsGaiaSignonRealm(const GURL& url) {
return url == GaiaUrls::GetInstance()->gaia_url();
}
+
+std::vector<std::string> ParseListAccountsData(const std::string& data) {
+ std::vector<std::string> account_ids;
+
+ // Parse returned data and make sure we have data.
+ scoped_ptr<base::Value> value(base::JSONReader::Read(data));
+ if (!value)
+ return account_ids;
+
+ base::ListValue* list;
+ if (!value->GetAsList(&list) || list->GetSize() < 2)
+ return account_ids;
+
+ // Get list of account info.
+ base::ListValue* accounts;
+ if (!list->GetList(1, &accounts) || accounts == NULL)
+ return account_ids;
+
+ // Build a vector of accounts from the cookie. Order is important: the first
+ // account in the list is the primary account.
+ for (size_t i = 0; i < accounts->GetSize(); ++i) {
+ base::ListValue* account;
+ if (accounts->GetList(i, &account) && account != NULL) {
+ std::string email;
+ if (account->GetString(3, &email) && !email.empty())
+ account_ids.push_back(email);
+ }
+ }
+
+ return account_ids;
+}
+
} // namespace gaia
diff --git a/google_apis/gaia/gaia_auth_util.h b/google_apis/gaia/gaia_auth_util.h
index 35e834b..354d116 100644
--- a/google_apis/gaia/gaia_auth_util.h
+++ b/google_apis/gaia/gaia_auth_util.h
@@ -6,6 +6,7 @@
#define GOOGLE_APIS_GAIA_GAIA_AUTH_UTIL_H_
#include <string>
+#include <vector>
class GURL;
@@ -34,6 +35,10 @@ std::string ExtractDomainName(const std::string& email);
bool IsGaiaSignonRealm(const GURL& url);
+// Parses JSON data returned by /ListAccounts call, returns vector of
+// accounts (email addresses).
+std::vector<std::string> ParseListAccountsData(const std::string& data);
+
} // namespace gaia
#endif // GOOGLE_APIS_GAIA_GAIA_AUTH_UTIL_H_
diff --git a/google_apis/gaia/gaia_auth_util_unittest.cc b/google_apis/gaia/gaia_auth_util_unittest.cc
index 4fe58a3..ebe8f87 100644
--- a/google_apis/gaia/gaia_auth_util_unittest.cc
+++ b/google_apis/gaia/gaia_auth_util_unittest.cc
@@ -108,4 +108,38 @@ TEST(GaiaAuthUtilTest, IsGaiaSignonRealm) {
EXPECT_FALSE(IsGaiaSignonRealm(GURL("https://www.example.com/")));
}
+TEST(GaiaAuthUtilTest, ParseListAccountsData) {
+ std::vector<std::string> accounts;
+ accounts = ParseListAccountsData("");
+ ASSERT_EQ(0u, accounts.size());
+
+ accounts = ParseListAccountsData("1");
+ ASSERT_EQ(0u, accounts.size());
+
+ accounts = ParseListAccountsData("[]");
+ ASSERT_EQ(0u, accounts.size());
+
+ accounts = ParseListAccountsData("[\"foo\", \"bar\"]");
+ ASSERT_EQ(0u, accounts.size());
+
+ accounts = ParseListAccountsData("[\"foo\", []]");
+ ASSERT_EQ(0u, accounts.size());
+
+ accounts = ParseListAccountsData(
+ "[\"foo\", [[\"bar\", 0, \"name\", 0, \"photo\", 0, 0, 0]]]");
+ ASSERT_EQ(0u, accounts.size());
+
+ accounts = ParseListAccountsData(
+ "[\"foo\", [[\"bar\", 0, \"name\", \"email\", \"photo\", 0, 0, 0]]]");
+ ASSERT_EQ(1u, accounts.size());
+ ASSERT_EQ("email", accounts[0]);
+
+ accounts = ParseListAccountsData(
+ "[\"foo\", [[\"bar1\", 0, \"name1\", \"email1\", \"photo1\", 0, 0, 0], "
+ "[\"bar2\", 0, \"name2\", \"email2\", \"photo2\", 0, 0, 0]]]");
+ ASSERT_EQ(2u, accounts.size());
+ ASSERT_EQ("email1", accounts[0]);
+ ASSERT_EQ("email2", accounts[1]);
+}
+
} // namespace gaia