OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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 <list> |
| 6 #include <utility> |
| 7 #include "base/compiler_specific.h" |
| 8 #include "base/file_util.h" |
| 9 #include "base/files/file_path.h" |
| 10 #include "base/memory/scoped_vector.h" |
| 11 #include "base/message_loop.h" |
| 12 #include "base/path_service.h" |
| 13 #include "base/stringprintf.h" |
| 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/values.h" |
| 16 #include "chrome/browser/component_updater/component_updater_service.h" |
| 17 #include "chrome/browser/component_updater/test/component_patcher_mock.h" |
| 18 #include "chrome/browser/component_updater/test/component_updater_service_unitte
st.h" |
| 19 #include "chrome/browser/component_updater/test/test_installer.h" |
| 20 #include "chrome/common/chrome_notification_types.h" |
| 21 #include "chrome/common/chrome_paths.h" |
| 22 #include "content/public/browser/notification_observer.h" |
| 23 #include "content/public/browser/notification_service.h" |
| 24 #include "content/public/test/test_browser_thread.h" |
| 25 #include "content/public/test/test_notification_tracker.h" |
| 26 #include "content/test/net/url_request_prepackaged_interceptor.h" |
| 27 #include "googleurl/src/gurl.h" |
| 28 #include "libxml/globals.h" |
| 29 #include "net/base/upload_bytes_element_reader.h" |
| 30 #include "net/url_request/url_fetcher.h" |
| 31 #include "net/url_request/url_request.h" |
| 32 #include "net/url_request/url_request_filter.h" |
| 33 #include "net/url_request/url_request_simple_job.h" |
| 34 #include "net/url_request/url_request_test_util.h" |
| 35 #include "testing/gtest/include/gtest/gtest.h" |
| 36 |
| 37 using content::BrowserThread; |
| 38 using content::TestNotificationTracker; |
| 39 |
| 40 // Verify that we can download and install a component and a differential |
| 41 // update to that component. We do three loops; the final loop should do |
| 42 // nothing. |
| 43 // We also check that exactly 5 network requests are issued: |
| 44 // 1- update check (response: v1 available) |
| 45 // 2- download crx (v1) |
| 46 // 3- update check (response: v2 available) |
| 47 // 4- download differential crx (v1 to v2) |
| 48 // 5- update check (response: no further update available) |
| 49 TEST_F(ComponentUpdaterTest, DifferentialUpdate) { |
| 50 base::MessageLoop message_loop; |
| 51 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
| 52 content::TestBrowserThread file_thread(BrowserThread::FILE); |
| 53 content::TestBrowserThread io_thread(BrowserThread::IO); |
| 54 |
| 55 io_thread.StartIOThread(); |
| 56 file_thread.Start(); |
| 57 |
| 58 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| 59 |
| 60 VersionedTestInstaller installer; |
| 61 CrxComponent com; |
| 62 RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), &installer); |
| 63 |
| 64 const GURL expected_update_url_0( |
| 65 "http://localhost/upd?extra=foo" |
| 66 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D0.0%26fp%3D%26uc"); |
| 67 const GURL expected_update_url_1( |
| 68 "http://localhost/upd?extra=foo" |
| 69 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D1.0%26fp%3D1%26uc"); |
| 70 const GURL expected_update_url_2( |
| 71 "http://localhost/upd?extra=foo" |
| 72 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D2.0%26fp%3Df22%26uc"); |
| 73 const GURL expected_crx_url_1( |
| 74 "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"); |
| 75 const GURL expected_crx_url_1_diff_2( |
| 76 "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"); |
| 77 |
| 78 interceptor.SetResponse(expected_update_url_0, |
| 79 test_file("updatecheck_diff_reply_1.xml")); |
| 80 interceptor.SetResponse(expected_update_url_1, |
| 81 test_file("updatecheck_diff_reply_2.xml")); |
| 82 interceptor.SetResponse(expected_update_url_2, |
| 83 test_file("updatecheck_diff_reply_3.xml")); |
| 84 interceptor.SetResponse(expected_crx_url_1, |
| 85 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx")); |
| 86 interceptor.SetResponse( |
| 87 expected_crx_url_1_diff_2, |
| 88 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx")); |
| 89 |
| 90 test_configurator()->SetLoopCount(3); |
| 91 |
| 92 component_updater()->Start(); |
| 93 message_loop.Run(); |
| 94 |
| 95 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
| 96 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); |
| 97 |
| 98 EXPECT_EQ(5, interceptor.GetHitCount()); |
| 99 |
| 100 component_updater()->Stop(); |
| 101 } |
OLD | NEW |