Home | History | Annotate | Download | only in webui
      1 // Copyright 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/browser/ui/webui/identity_internals_ui_browsertest.h"
      6 
      7 #include "base/strings/string_number_conversions.h"
      8 #include "base/time/time.h"
      9 #include "chrome/browser/extensions/api/identity/identity_api.h"
     10 #include "chrome/browser/profiles/profile.h"
     11 #include "chrome/browser/ui/browser.h"
     12 
     13 namespace {
     14 
     15 const char kChromeWebStoreId[] = "ahfgeienlihckogmohjhadlkjgocpleb";
     16 const int kOneHour = 3600;
     17 } // namespace
     18 
     19 IdentityInternalsUIBrowserTest::IdentityInternalsUIBrowserTest() {}
     20 
     21 IdentityInternalsUIBrowserTest::~IdentityInternalsUIBrowserTest() {}
     22 
     23 void IdentityInternalsUIBrowserTest::SetupTokenCache(int number_of_tokens) {
     24   for (int number = 0; number < number_of_tokens; ++number) {
     25     const std::string token_number = base::IntToString(number);
     26     std::string token_id("token");
     27     token_id += token_number;
     28     std::string extension_id("extension");
     29     extension_id += token_number;
     30     std::vector<std::string> scopes;
     31     scopes.push_back(std::string("scope_1_") + token_number);
     32     scopes.push_back(std::string("scope_2_") + token_number);
     33     AddTokenToCache(token_id, extension_id, scopes, kOneHour);
     34   }
     35 }
     36 
     37 void IdentityInternalsUIBrowserTest::SetupTokenCacheWithStoreApp() {
     38   std::vector<std::string> scopes;
     39   scopes.push_back(std::string("store_scope1"));
     40   scopes.push_back(std::string("store_scope2"));
     41   AddTokenToCache("store_token", kChromeWebStoreId, scopes, kOneHour);
     42 }
     43 
     44 void IdentityInternalsUIBrowserTest::AddTokenToCache(
     45     const std::string token_id,
     46     const std::string extension_id,
     47     const std::vector<std::string>& scopes,
     48     int time_to_live) {
     49   extensions::IdentityTokenCacheValue token_cache_value =
     50       extensions::IdentityTokenCacheValue(token_id,
     51           base::TimeDelta::FromSeconds(time_to_live));
     52   extensions::IdentityAPI::GetFactoryInstance()->
     53       GetForProfile(browser()->profile())->
     54           SetCachedToken(extension_id, scopes, token_cache_value);
     55 }
     56 
     57