1868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 2868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// found in the LICENSE file. 4868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 5868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "chrome/browser/ui/webui/identity_internals_ui_browsertest.h" 6868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 7868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/string_number_conversions.h" 8eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/time/time.h" 9a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "chrome/browser/extensions/api/identity/extension_token_key.h" 10868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "chrome/browser/extensions/api/identity/identity_api.h" 11868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "chrome/browser/profiles/profile.h" 12868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "chrome/browser/ui/browser.h" 13868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 14868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)namespace { 15868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 16868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)const char kChromeWebStoreId[] = "ahfgeienlihckogmohjhadlkjgocpleb"; 17868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)const int kOneHour = 3600; 18868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} // namespace 19868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 20868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)IdentityInternalsUIBrowserTest::IdentityInternalsUIBrowserTest() {} 21868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 22868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)IdentityInternalsUIBrowserTest::~IdentityInternalsUIBrowserTest() {} 23868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 24868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)void IdentityInternalsUIBrowserTest::SetupTokenCache(int number_of_tokens) { 25868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) for (int number = 0; number < number_of_tokens; ++number) { 26868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const std::string token_number = base::IntToString(number); 27868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) std::string token_id("token"); 28868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) token_id += token_number; 29868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) std::string extension_id("extension"); 30868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) extension_id += token_number; 31868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) std::vector<std::string> scopes; 32868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) scopes.push_back(std::string("scope_1_") + token_number); 33868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) scopes.push_back(std::string("scope_2_") + token_number); 34868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) AddTokenToCache(token_id, extension_id, scopes, kOneHour); 35868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) } 36868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 37868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 38868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)void IdentityInternalsUIBrowserTest::SetupTokenCacheWithStoreApp() { 39868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) std::vector<std::string> scopes; 40868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) scopes.push_back(std::string("store_scope1")); 41868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) scopes.push_back(std::string("store_scope2")); 42868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) AddTokenToCache("store_token", kChromeWebStoreId, scopes, kOneHour); 43868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 44868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 45868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)void IdentityInternalsUIBrowserTest::AddTokenToCache( 46868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const std::string token_id, 47868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const std::string extension_id, 48868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const std::vector<std::string>& scopes, 49868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) int time_to_live) { 50868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) extensions::IdentityTokenCacheValue token_cache_value = 51868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) extensions::IdentityTokenCacheValue(token_id, 52868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) base::TimeDelta::FromSeconds(time_to_live)); 53a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) extensions::ExtensionTokenKey key( 54a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) extension_id, 55a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) "test@example.com", 56a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) std::set<std::string>(scopes.begin(), scopes.end())); 57a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) extensions::IdentityAPI::GetFactoryInstance() 58a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ->Get(browser()->profile()) 59a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ->SetCachedToken(key, token_cache_value); 60868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 61