| 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 <list> | 5 #include <list> |
| 6 #include <set> | 6 #include <set> |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/scoped_observer.h" | 9 #include "base/scoped_observer.h" |
| 10 #include "chrome/browser/extensions/extension_browsertest.h" | 10 #include "chrome/browser/extensions/extension_browsertest.h" |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 base::FilePath(FILE_PATH_LITERAL("page.html")), | 318 base::FilePath(FILE_PATH_LITERAL("page.html")), |
| 319 JobObserver::Result::SUCCESS); | 319 JobObserver::Result::SUCCESS); |
| 320 job_observer.ExpectJobResult(id, base::FilePath(FILE_PATH_LITERAL("page.js")), | 320 job_observer.ExpectJobResult(id, base::FilePath(FILE_PATH_LITERAL("page.js")), |
| 321 JobObserver::Result::SUCCESS); | 321 JobObserver::Result::SUCCESS); |
| 322 job_observer.ExpectJobResult( | 322 job_observer.ExpectJobResult( |
| 323 id, base::FilePath(FILE_PATH_LITERAL("dir/page2.html")), | 323 id, base::FilePath(FILE_PATH_LITERAL("dir/page2.html")), |
| 324 JobObserver::Result::SUCCESS); | 324 JobObserver::Result::SUCCESS); |
| 325 job_observer.ExpectJobResult(id, | 325 job_observer.ExpectJobResult(id, |
| 326 base::FilePath(FILE_PATH_LITERAL("page2.js")), | 326 base::FilePath(FILE_PATH_LITERAL("page2.js")), |
| 327 JobObserver::Result::SUCCESS); | 327 JobObserver::Result::SUCCESS); |
| 328 job_observer.ExpectJobResult(id, base::FilePath(FILE_PATH_LITERAL("cs1.js")), |
| 329 JobObserver::Result::SUCCESS); |
| 330 job_observer.ExpectJobResult(id, base::FilePath(FILE_PATH_LITERAL("cs2.js")), |
| 331 JobObserver::Result::SUCCESS); |
| 332 |
| 333 VerifierObserver verifier_observer; |
| 334 ContentVerifier::SetObserverForTests(&verifier_observer); |
| 328 | 335 |
| 329 // Install a test extension we copied from the webstore that has actual | 336 // Install a test extension we copied from the webstore that has actual |
| 330 // signatures, and contains image paths with leading "./". | 337 // signatures, and contains paths with a leading "./" in various places. |
| 331 const Extension* extension = InstallExtensionFromWebstore( | 338 const Extension* extension = InstallExtensionFromWebstore( |
| 332 test_data_dir_.AppendASCII("content_verifier/dot_slash_paths.crx"), 1); | 339 test_data_dir_.AppendASCII("content_verifier/dot_slash_paths.crx"), 1); |
| 333 | 340 |
| 334 ASSERT_TRUE(extension); | 341 ASSERT_TRUE(extension); |
| 335 ASSERT_EQ(extension->id(), id); | 342 ASSERT_EQ(extension->id(), id); |
| 336 | 343 |
| 344 // The content scripts might fail verification the first time since the |
| 345 // one-time processing might not be finished yet - if that's the case then |
| 346 // we want to wait until that work is done. |
| 347 if (!ContainsKey(verifier_observer.completed_fetches(), id)) |
| 348 verifier_observer.WaitForFetchComplete(id); |
| 349 |
| 350 // Now disable/re-enable the extension to cause the content scripts to be |
| 351 // read again. |
| 352 DisableExtension(id); |
| 353 EnableExtension(id); |
| 354 |
| 337 EXPECT_TRUE(job_observer.WaitForExpectedJobs()); | 355 EXPECT_TRUE(job_observer.WaitForExpectedJobs()); |
| 338 | 356 |
| 339 ContentVerifyJob::SetObserverForTests(NULL); | 357 ContentVerifyJob::SetObserverForTests(NULL); |
| 340 } | 358 } |
| 341 | 359 |
| 342 IN_PROC_BROWSER_TEST_F(ContentVerifierTest, ContentScripts) { | 360 IN_PROC_BROWSER_TEST_F(ContentVerifierTest, ContentScripts) { |
| 343 VerifierObserver verifier_observer; | 361 VerifierObserver verifier_observer; |
| 344 ContentVerifier::SetObserverForTests(&verifier_observer); | 362 ContentVerifier::SetObserverForTests(&verifier_observer); |
| 345 | 363 |
| 346 // Install an extension with content scripts. The initial read of the content | 364 // Install an extension with content scripts. The initial read of the content |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 job_observer.ExpectJobResult(id, | 399 job_observer.ExpectJobResult(id, |
| 382 base::FilePath(FILE_PATH_LITERAL("script.js")), | 400 base::FilePath(FILE_PATH_LITERAL("script.js")), |
| 383 JobObserver::Result::FAILURE); | 401 JobObserver::Result::FAILURE); |
| 384 EnableExtension(id); | 402 EnableExtension(id); |
| 385 EXPECT_TRUE(job_observer.WaitForExpectedJobs()); | 403 EXPECT_TRUE(job_observer.WaitForExpectedJobs()); |
| 386 | 404 |
| 387 ContentVerifyJob::SetObserverForTests(NULL); | 405 ContentVerifyJob::SetObserverForTests(NULL); |
| 388 } | 406 } |
| 389 | 407 |
| 390 } // namespace extensions | 408 } // namespace extensions |
| OLD | NEW |