| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/copresence/chrome_whispernet_client.h" | 5 #include "chrome/browser/copresence/chrome_whispernet_client.h" |
| 6 | 6 |
| 7 #include <cstdlib> | 7 #include <cstdlib> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 for (int si = 0, di = ch; si < source->frames(); ++si, di += channels) | 47 for (int si = 0, di = ch; si < source->frames(); ++si, di += channels) |
| 48 buffer_view[di] = source->channel(ch)[si]; | 48 buffer_view[di] = source->channel(ch)[si]; |
| 49 } | 49 } |
| 50 | 50 |
| 51 return buffer; | 51 return buffer; |
| 52 } | 52 } |
| 53 | 53 |
| 54 } // namespace | 54 } // namespace |
| 55 | 55 |
| 56 class ChromeWhispernetClientTest : public ExtensionBrowserTest { | 56 class ChromeWhispernetClientTest : public ExtensionBrowserTest { |
| 57 public: | 57 protected: |
| 58 ChromeWhispernetClientTest() | 58 ChromeWhispernetClientTest() |
| 59 : context_(NULL), expected_audible_(false), initialized_(false) {} | 59 : context_(NULL), expected_audible_(false), initialized_(false) {} |
| 60 | 60 |
| 61 ~ChromeWhispernetClientTest() override {} | 61 ~ChromeWhispernetClientTest() override {} |
| 62 | 62 |
| 63 void InitializeWhispernet() { | 63 void InitializeWhispernet() { |
| 64 context_ = browser()->profile(); | 64 context_ = browser()->profile(); |
| 65 run_loop_.reset(new base::RunLoop()); | 65 run_loop_.reset(new base::RunLoop()); |
| 66 GetWhispernetClient(context_)->Initialize(base::Bind( | 66 GetWhispernetClient(context_)->Initialize(base::Bind( |
| 67 &ChromeWhispernetClientTest::InitCallback, base::Unretained(this))); | 67 &ChromeWhispernetClientTest::InitCallback, base::Unretained(this))); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 ASSERT_TRUE(client); | 123 ASSERT_TRUE(client); |
| 124 | 124 |
| 125 run_loop_.reset(new base::RunLoop()); | 125 run_loop_.reset(new base::RunLoop()); |
| 126 client->RegisterDetectBroadcastCallback( | 126 client->RegisterDetectBroadcastCallback( |
| 127 base::Bind(&ChromeWhispernetClientTest::DetectBroadcastCallback, | 127 base::Bind(&ChromeWhispernetClientTest::DetectBroadcastCallback, |
| 128 base::Unretained(this))); | 128 base::Unretained(this))); |
| 129 client->DetectBroadcast(); | 129 client->DetectBroadcast(); |
| 130 run_loop_->Run(); | 130 run_loop_->Run(); |
| 131 } | 131 } |
| 132 | 132 |
| 133 protected: | |
| 134 void InitCallback(bool success) { | 133 void InitCallback(bool success) { |
| 135 EXPECT_TRUE(success); | 134 EXPECT_TRUE(success); |
| 136 initialized_ = true; | 135 initialized_ = true; |
| 137 ASSERT_TRUE(run_loop_); | 136 ASSERT_TRUE(run_loop_); |
| 138 run_loop_->Quit(); | 137 run_loop_->Quit(); |
| 139 } | 138 } |
| 140 | 139 |
| 141 void SamplesCallback( | 140 void SamplesCallback( |
| 142 copresence::AudioType type, | 141 copresence::AudioType type, |
| 143 const std::string& token, | 142 const std::string& token, |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 IN_PROC_BROWSER_TEST_F(ChromeWhispernetClientTest, MAYBE_TokenLengths) { | 223 IN_PROC_BROWSER_TEST_F(ChromeWhispernetClientTest, MAYBE_TokenLengths) { |
| 225 InitializeWhispernet(); | 224 InitializeWhispernet(); |
| 226 size_t kLongTokenLengths[2] = {8, 9}; | 225 size_t kLongTokenLengths[2] = {8, 9}; |
| 227 | 226 |
| 228 EncodeTokenAndSaveSamples(true, kEightZeros); | 227 EncodeTokenAndSaveSamples(true, kEightZeros); |
| 229 DecodeSamplesAndVerifyToken(true, kEightZeros, kLongTokenLengths); | 228 DecodeSamplesAndVerifyToken(true, kEightZeros, kLongTokenLengths); |
| 230 | 229 |
| 231 EncodeTokenAndSaveSamples(false, kNineZeros); | 230 EncodeTokenAndSaveSamples(false, kNineZeros); |
| 232 DecodeSamplesAndVerifyToken(false, kNineZeros, kLongTokenLengths); | 231 DecodeSamplesAndVerifyToken(false, kNineZeros, kLongTokenLengths); |
| 233 } | 232 } |
| OLD | NEW |