Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // Fuzzer for content/renderer | |
| 6 | |
| 7 #include <stddef.h> | |
| 8 #include <stdint.h> | |
| 9 #include <memory> | |
| 10 | |
| 11 #include "base/feature_list.h" | |
| 12 #include "content/common/navigation_params.h" | |
| 13 #include "content/public/test/render_view_test.h" | |
| 14 #include "content/renderer/render_view_impl.h" | |
| 15 #include "content/test/test_render_frame.h" | |
| 16 #include "gin/v8_initializer.h" | |
| 17 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | |
| 18 | |
| 19 namespace content { | |
| 20 | |
| 21 class FuzzerRenderTest : public RenderViewTest { | |
| 22 public: | |
| 23 FuzzerRenderTest() : RenderViewTest() {} | |
| 24 void TestBody() override {} | |
| 25 | |
| 26 void SetUp() override { RenderViewTest::SetUp(); } | |
| 27 | |
| 28 TestRenderFrame* frame() { | |
| 29 return static_cast<TestRenderFrame*>(view_->GetMainRenderFrame()); | |
| 30 } | |
| 31 | |
| 32 private: | |
| 33 DISALLOW_COPY_AND_ASSIGN(FuzzerRenderTest); | |
| 34 }; | |
| 35 | |
| 36 struct Env { | |
| 37 Env() { | |
| 38 base::CommandLine::Init(0, nullptr); | |
| 39 base::FeatureList::InitializeInstance(std::string(), std::string()); | |
| 40 | |
| 41 blink::WebRuntimeFeatures::enableExperimentalFeatures(true); | |
| 42 blink::WebRuntimeFeatures::enableTestOnlyFeatures(true); | |
| 43 gin::V8Initializer::LoadV8Snapshot(); | |
| 44 gin::V8Initializer::LoadV8Natives(); | |
| 45 | |
| 46 test.reset(new FuzzerRenderTest()); | |
| 47 test->SetUp(); | |
| 48 } | |
| 49 | |
| 50 TestRenderFrame* frame() { return test->frame(); } | |
| 51 | |
| 52 std::unique_ptr<FuzzerRenderTest> test; | |
| 53 | |
| 54 private: | |
| 55 DISALLOW_COPY_AND_ASSIGN(Env); | |
| 56 }; | |
| 57 | |
| 58 static Env* env = new Env(); | |
| 59 | |
| 60 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { | |
| 61 std::string input(reinterpret_cast<const char*>(data), size); | |
| 62 | |
| 63 CommonNavigationParams common_params; | |
| 64 common_params.navigation_type = FrameMsg_Navigate_Type::NORMAL; | |
| 65 common_params.url = GURL("data:text/html," + input); | |
|
mmoroz
2016/06/03 14:32:46
I guess we need a dictionary for HTML? I will try
aizatsky
2016/06/03 19:04:01
Sure. Though my long-term plan is to explore struc
| |
| 66 env->frame()->Navigate(common_params, StartNavigationParams(), | |
| 67 RequestNavigationParams()); | |
| 68 | |
| 69 return 0; | |
| 70 } | |
| 71 | |
| 72 } // namespace content | |
|
mmoroz
2016/06/03 14:32:46
Does it make sense to have 'extern "C" int LLVMFuz
aizatsky
2016/06/03 19:04:01
Yes. It let's you not to write "content::" all the
| |
| OLD | NEW |