| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "core/loader/ProgressTracker.h" | 5 #include "core/loader/ProgressTracker.h" |
| 6 | 6 |
| 7 #include "core/frame/Settings.h" | 7 #include "core/frame/Settings.h" |
| 8 #include "core/loader/EmptyClients.h" | 8 #include "core/loader/EmptyClients.h" |
| 9 #include "core/testing/DummyPageHolder.h" | 9 #include "core/testing/DummyPageHolder.h" |
| 10 #include "platform/network/ResourceResponse.h" | 10 #include "platform/network/ResourceResponse.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 | 45 |
| 46 LocalFrame& frame() const { return m_dummyPageHolder->frame(); } | 46 LocalFrame& frame() const { return m_dummyPageHolder->frame(); } |
| 47 ProgressTracker& progress() const { return frame().loader().progress(); } | 47 ProgressTracker& progress() const { return frame().loader().progress(); } |
| 48 double lastProgress() const { return m_client->lastProgress(); } | 48 double lastProgress() const { return m_client->lastProgress(); } |
| 49 const ResourceResponse& responseHeaders() const { return m_response; } | 49 const ResourceResponse& responseHeaders() const { return m_response; } |
| 50 | 50 |
| 51 // Reports a 1024-byte "main resource" (VeryHigh priority) request/response | 51 // Reports a 1024-byte "main resource" (VeryHigh priority) request/response |
| 52 // to ProgressTracker with identifier 1, but tests are responsible for | 52 // to ProgressTracker with identifier 1, but tests are responsible for |
| 53 // emulating payload and load completion. | 53 // emulating payload and load completion. |
| 54 void emulateMainResourceRequestAndResponse() const { | 54 void emulateMainResourceRequestAndResponse() const { |
| 55 progress().progressStarted(); | 55 progress().progressStarted(FrameLoadTypeStandard); |
| 56 progress().willStartLoading(1ul, ResourceLoadPriorityVeryHigh); | 56 progress().willStartLoading(1ul, ResourceLoadPriorityVeryHigh); |
| 57 EXPECT_EQ(0.0, lastProgress()); | 57 EXPECT_EQ(0.0, lastProgress()); |
| 58 progress().incrementProgress(1ul, responseHeaders()); | 58 progress().incrementProgress(1ul, responseHeaders()); |
| 59 EXPECT_EQ(0.0, lastProgress()); | 59 EXPECT_EQ(0.0, lastProgress()); |
| 60 } | 60 } |
| 61 | 61 |
| 62 private: | 62 private: |
| 63 Persistent<ProgressClient> m_client; | 63 Persistent<ProgressClient> m_client; |
| 64 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; | 64 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; |
| 65 ResourceResponse m_response; | 65 ResourceResponse m_response; |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 TEST_F(ProgressTrackerTest, Static) { | 68 TEST_F(ProgressTrackerTest, Static) { |
| 69 progress().progressStarted(); | 69 progress().progressStarted(FrameLoadTypeStandard); |
| 70 EXPECT_EQ(0.0, lastProgress()); | 70 EXPECT_EQ(0.0, lastProgress()); |
| 71 progress().finishedParsing(); | 71 progress().finishedParsing(); |
| 72 EXPECT_EQ(1.0, lastProgress()); | 72 EXPECT_EQ(1.0, lastProgress()); |
| 73 } | 73 } |
| 74 | 74 |
| 75 TEST_F(ProgressTrackerTest, MainResourceOnly) { | 75 TEST_F(ProgressTrackerTest, MainResourceOnly) { |
| 76 emulateMainResourceRequestAndResponse(); | 76 emulateMainResourceRequestAndResponse(); |
| 77 | 77 |
| 78 // .2 for committing, .25 out of .5 possible for bytes received. | 78 // .2 for committing, .25 out of .5 possible for bytes received. |
| 79 progress().incrementProgress(1ul, 512); | 79 progress().incrementProgress(1ul, 512); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 // .2 for finishing parsing, .5 for all bytes received. | 117 // .2 for finishing parsing, .5 for all bytes received. |
| 118 // Medium priority resource is ignored. | 118 // Medium priority resource is ignored. |
| 119 progress().completeProgress(1ul); | 119 progress().completeProgress(1ul); |
| 120 EXPECT_EQ(0.7, lastProgress()); | 120 EXPECT_EQ(0.7, lastProgress()); |
| 121 | 121 |
| 122 progress().finishedParsing(); | 122 progress().finishedParsing(); |
| 123 EXPECT_EQ(1.0, lastProgress()); | 123 EXPECT_EQ(1.0, lastProgress()); |
| 124 } | 124 } |
| 125 | 125 |
| 126 } // namespace blink | 126 } // namespace blink |
| OLD | NEW |