| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/geolocation/access_token_store.h" | 5 #include "chrome/browser/geolocation/access_token_store.h" |
| 6 | 6 |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/browser_thread.h" | 9 #include "chrome/browser/browser_thread.h" |
| 10 #include "chrome/test/in_process_browser_test.h" | 10 #include "chrome/test/in_process_browser_test.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 } | 50 } |
| 51 | 51 |
| 52 struct TokenLoadClientForTest { | 52 struct TokenLoadClientForTest { |
| 53 void NotReachedCallback(AccessTokenStore::AccessTokenSet /*tokens*/) { | 53 void NotReachedCallback(AccessTokenStore::AccessTokenSet /*tokens*/) { |
| 54 NOTREACHED() << "This request should have been canceled before callback"; | 54 NOTREACHED() << "This request should have been canceled before callback"; |
| 55 } | 55 } |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 void RunCancelTestInClientTread() { | 58 void RunCancelTestInClientTread() { |
| 59 ASSERT_TRUE(BrowserThread::CurrentlyOn(kExpectedClientThreadId)); | 59 ASSERT_TRUE(BrowserThread::CurrentlyOn(kExpectedClientThreadId)); |
| 60 scoped_refptr<AccessTokenStore> store = NewChromePrefsAccessTokenStore(); | 60 scoped_refptr<AccessTokenStore> store(NewChromePrefsAccessTokenStore()); |
| 61 CancelableRequestConsumer consumer; | 61 CancelableRequestConsumer consumer; |
| 62 TokenLoadClientForTest load_client; | 62 TokenLoadClientForTest load_client; |
| 63 | 63 |
| 64 // Single request, canceled explicitly | 64 // Single request, canceled explicitly |
| 65 CancelableRequestProvider::Handle first_handle = | 65 CancelableRequestProvider::Handle first_handle = |
| 66 store->LoadAccessTokens(&consumer, NewCallback( | 66 store->LoadAccessTokens(&consumer, NewCallback( |
| 67 &load_client, &TokenLoadClientForTest::NotReachedCallback)); | 67 &load_client, &TokenLoadClientForTest::NotReachedCallback)); |
| 68 EXPECT_TRUE(consumer.HasPendingRequests()); | 68 EXPECT_TRUE(consumer.HasPendingRequests()); |
| 69 // Test this handle is valid. | 69 // Test this handle is valid. |
| 70 consumer.GetClientData(store.get(), first_handle); | 70 consumer.GetClientData(store.get(), first_handle); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 AccessTokenStore::AccessTokenSet::const_iterator item = | 110 AccessTokenStore::AccessTokenSet::const_iterator item = |
| 111 access_token_set.find(ref_url_); | 111 access_token_set.find(ref_url_); |
| 112 if (!token_to_expect_) { | 112 if (!token_to_expect_) { |
| 113 EXPECT_TRUE(item == access_token_set.end()); | 113 EXPECT_TRUE(item == access_token_set.end()); |
| 114 } else { | 114 } else { |
| 115 EXPECT_FALSE(item == access_token_set.end()); | 115 EXPECT_FALSE(item == access_token_set.end()); |
| 116 EXPECT_EQ(*token_to_expect_, item->second); | 116 EXPECT_EQ(*token_to_expect_, item->second); |
| 117 } | 117 } |
| 118 | 118 |
| 119 if (token_to_set_) { | 119 if (token_to_set_) { |
| 120 scoped_refptr<AccessTokenStore> store = | 120 scoped_refptr<AccessTokenStore> store( |
| 121 NewChromePrefsAccessTokenStore(); | 121 NewChromePrefsAccessTokenStore()); |
| 122 store->SaveAccessToken(ref_url_, *token_to_set_); | 122 store->SaveAccessToken(ref_url_, *token_to_set_); |
| 123 } | 123 } |
| 124 BrowserThread::PostTask( | 124 BrowserThread::PostTask( |
| 125 BrowserThread::UI, FROM_HERE, new MessageLoop::QuitTask); | 125 BrowserThread::UI, FROM_HERE, new MessageLoop::QuitTask); |
| 126 } | 126 } |
| 127 | 127 |
| 128 IN_PROC_BROWSER_TEST_F(GeolocationAccessTokenStoreTest, SetAcrossInstances) { | 128 IN_PROC_BROWSER_TEST_F(GeolocationAccessTokenStoreTest, SetAcrossInstances) { |
| 129 const string16 ref_token1 = ASCIIToUTF16("jksdfo90,'s#\"#1*("); | 129 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"); | 130 const string16 ref_token2 = ASCIIToUTF16("\1\2\3\4\5\6\7\10\11\12=023"); |
| 131 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 131 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 142 DoTestStepAndWaitForResults(kRefServerUrl2, &ref_token2, NULL); | 142 DoTestStepAndWaitForResults(kRefServerUrl2, &ref_token2, NULL); |
| 143 DoTestStepAndWaitForResults(kRefServerUrl1, &ref_token1, NULL); | 143 DoTestStepAndWaitForResults(kRefServerUrl1, &ref_token1, NULL); |
| 144 } | 144 } |
| 145 | 145 |
| 146 IN_PROC_BROWSER_TEST_F(GeolocationAccessTokenStoreTest, CancelRequest) { | 146 IN_PROC_BROWSER_TEST_F(GeolocationAccessTokenStoreTest, CancelRequest) { |
| 147 BrowserThread::PostTask( | 147 BrowserThread::PostTask( |
| 148 kExpectedClientThreadId, FROM_HERE, NewRunnableFunction( | 148 kExpectedClientThreadId, FROM_HERE, NewRunnableFunction( |
| 149 RunCancelTestInClientTread)); | 149 RunCancelTestInClientTread)); |
| 150 ui_test_utils::RunMessageLoop(); | 150 ui_test_utils::RunMessageLoop(); |
| 151 } | 151 } |
| OLD | NEW |