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

Side by Side Diff: chrome/browser/geolocation/access_token_store_browsertest.cc

Issue 7734005: Get rid of the link time dependency between content and chrome through the geolocation code. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/geolocation/access_token_store.h"
6
7 #include "base/string_util.h" 5 #include "base/string_util.h"
8 #include "base/utf_string_conversions.h" 6 #include "base/utf_string_conversions.h"
7 #include "chrome/browser/geolocation/chrome_access_token_store.h"
9 #include "chrome/test/base/in_process_browser_test.h" 8 #include "chrome/test/base/in_process_browser_test.h"
10 #include "chrome/test/base/ui_test_utils.h" 9 #include "chrome/test/base/ui_test_utils.h"
11 #include "content/browser/browser_thread.h" 10 #include "content/browser/browser_thread.h"
12 11
13 namespace { 12 namespace {
14 13
15 // The token store factory implementation expects to be used from any well-known 14 // The token store factory implementation expects to be used from any well-known
16 // chrome thread other than UI. We could use any arbitrary thread; IO is 15 // chrome thread other than UI. We could use any arbitrary thread; IO is
17 // a good choice as this is the expected usage. 16 // a good choice as this is the expected usage.
18 const BrowserThread::ID kExpectedClientThreadId = BrowserThread::IO; 17 const BrowserThread::ID kExpectedClientThreadId = BrowserThread::IO;
(...skipping 19 matching lines...) Expand all
38 const string16* token_to_expect_; 37 const string16* token_to_expect_;
39 const string16* token_to_set_; 38 const string16* token_to_set_;
40 }; 39 };
41 40
42 void StartTestStepFromClientThread( 41 void StartTestStepFromClientThread(
43 scoped_refptr<AccessTokenStore>* store, 42 scoped_refptr<AccessTokenStore>* store,
44 CancelableRequestConsumerBase* consumer, 43 CancelableRequestConsumerBase* consumer,
45 AccessTokenStore::LoadAccessTokensCallbackType* callback) { 44 AccessTokenStore::LoadAccessTokensCallbackType* callback) {
46 ASSERT_TRUE(BrowserThread::CurrentlyOn(kExpectedClientThreadId)); 45 ASSERT_TRUE(BrowserThread::CurrentlyOn(kExpectedClientThreadId));
47 if (*store == NULL) 46 if (*store == NULL)
48 (*store) = NewChromePrefsAccessTokenStore(); 47 (*store) = new ChromeAccessTokenStore();
49 (*store)->LoadAccessTokens(consumer, callback); 48 (*store)->LoadAccessTokens(consumer, callback);
50 } 49 }
51 50
52 struct TokenLoadClientForTest { 51 struct TokenLoadClientForTest {
53 void NotReachedCallback(AccessTokenStore::AccessTokenSet /*tokens*/) { 52 void NotReachedCallback(AccessTokenStore::AccessTokenSet /*tokens*/) {
54 NOTREACHED() << "This request should have been canceled before callback"; 53 NOTREACHED() << "This request should have been canceled before callback";
55 } 54 }
56 }; 55 };
57 56
58 void RunCancelTestInClientTread() { 57 void RunCancelTestInClientTread() {
59 ASSERT_TRUE(BrowserThread::CurrentlyOn(kExpectedClientThreadId)); 58 ASSERT_TRUE(BrowserThread::CurrentlyOn(kExpectedClientThreadId));
60 scoped_refptr<AccessTokenStore> store(NewChromePrefsAccessTokenStore()); 59 scoped_refptr<AccessTokenStore> store(new ChromeAccessTokenStore());
61 CancelableRequestConsumer consumer; 60 CancelableRequestConsumer consumer;
62 TokenLoadClientForTest load_client; 61 TokenLoadClientForTest load_client;
63 62
64 // Single request, canceled explicitly 63 // Single request, canceled explicitly
65 CancelableRequestProvider::Handle first_handle = 64 CancelableRequestProvider::Handle first_handle =
66 store->LoadAccessTokens(&consumer, NewCallback( 65 store->LoadAccessTokens(&consumer, NewCallback(
67 &load_client, &TokenLoadClientForTest::NotReachedCallback)); 66 &load_client, &TokenLoadClientForTest::NotReachedCallback));
68 EXPECT_TRUE(consumer.HasPendingRequests()); 67 EXPECT_TRUE(consumer.HasPendingRequests());
69 // Test this handle is valid. 68 // Test this handle is valid.
70 consumer.GetClientData(store.get(), first_handle); 69 consumer.GetClientData(store.get(), first_handle);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 AccessTokenStore::AccessTokenSet::const_iterator item = 109 AccessTokenStore::AccessTokenSet::const_iterator item =
111 access_token_set.find(ref_url_); 110 access_token_set.find(ref_url_);
112 if (!token_to_expect_) { 111 if (!token_to_expect_) {
113 EXPECT_TRUE(item == access_token_set.end()); 112 EXPECT_TRUE(item == access_token_set.end());
114 } else { 113 } else {
115 EXPECT_FALSE(item == access_token_set.end()); 114 EXPECT_FALSE(item == access_token_set.end());
116 EXPECT_EQ(*token_to_expect_, item->second); 115 EXPECT_EQ(*token_to_expect_, item->second);
117 } 116 }
118 117
119 if (token_to_set_) { 118 if (token_to_set_) {
120 scoped_refptr<AccessTokenStore> store( 119 scoped_refptr<AccessTokenStore> store(new ChromeAccessTokenStore());
121 NewChromePrefsAccessTokenStore());
122 store->SaveAccessToken(ref_url_, *token_to_set_); 120 store->SaveAccessToken(ref_url_, *token_to_set_);
123 } 121 }
124 BrowserThread::PostTask( 122 BrowserThread::PostTask(
125 BrowserThread::UI, FROM_HERE, new MessageLoop::QuitTask); 123 BrowserThread::UI, FROM_HERE, new MessageLoop::QuitTask);
126 } 124 }
127 125
128 IN_PROC_BROWSER_TEST_F(GeolocationAccessTokenStoreTest, SetAcrossInstances) { 126 IN_PROC_BROWSER_TEST_F(GeolocationAccessTokenStoreTest, SetAcrossInstances) {
129 const string16 ref_token1 = ASCIIToUTF16("jksdfo90,'s#\"#1*("); 127 const string16 ref_token1 = ASCIIToUTF16("jksdfo90,'s#\"#1*(");
130 const string16 ref_token2 = ASCIIToUTF16("\1\2\3\4\5\6\7\10\11\12=023"); 128 const string16 ref_token2 = ASCIIToUTF16("\1\2\3\4\5\6\7\10\11\12=023");
131 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); 129 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 12 matching lines...) Expand all
144 } 142 }
145 143
146 IN_PROC_BROWSER_TEST_F(GeolocationAccessTokenStoreTest, CancelRequest) { 144 IN_PROC_BROWSER_TEST_F(GeolocationAccessTokenStoreTest, CancelRequest) {
147 BrowserThread::PostTask( 145 BrowserThread::PostTask(
148 kExpectedClientThreadId, FROM_HERE, NewRunnableFunction( 146 kExpectedClientThreadId, FROM_HERE, NewRunnableFunction(
149 RunCancelTestInClientTread)); 147 RunCancelTestInClientTread));
150 ui_test_utils::RunMessageLoop(); 148 ui_test_utils::RunMessageLoop();
151 } 149 }
152 150
153 } // namespace 151 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/geolocation/access_token_store.cc ('k') | chrome/browser/geolocation/chrome_access_token_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698