| 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 "bindings/core/v8/ScriptController.h" | 5 #include "bindings/core/v8/ScriptController.h" |
| 6 #include "bindings/core/v8/ScriptSourceCode.h" | 6 #include "bindings/core/v8/ScriptSourceCode.h" |
| 7 #include "bindings/core/v8/V8Binding.h" | 7 #include "bindings/core/v8/V8Binding.h" |
| 8 #include "bindings/core/v8/V8DOMActivityLogger.h" | 8 #include "bindings/core/v8/V8DOMActivityLogger.h" |
| 9 #include "public/web/WebCache.h" | 9 #include "public/web/WebCache.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 void executeScriptInMainWorld(const String& script) const | 76 void executeScriptInMainWorld(const String& script) const |
| 77 { | 77 { |
| 78 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 78 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
| 79 m_scriptController->executeScriptInMainWorld(script); | 79 m_scriptController->executeScriptInMainWorld(script); |
| 80 pumpPendingRequestsDoNotUse(m_webViewHelper.webViewImpl()->mainFrame()); | 80 pumpPendingRequestsDoNotUse(m_webViewHelper.webViewImpl()->mainFrame()); |
| 81 } | 81 } |
| 82 | 82 |
| 83 void executeScriptInIsolatedWorld(const String& script) const | 83 void executeScriptInIsolatedWorld(const String& script) const |
| 84 { | 84 { |
| 85 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 85 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
| 86 WillBeHeapVector<ScriptSourceCode> sources; | 86 HeapVector<ScriptSourceCode> sources; |
| 87 sources.append(ScriptSourceCode(script)); | 87 sources.append(ScriptSourceCode(script)); |
| 88 Vector<v8::Local<v8::Value>> results; | 88 Vector<v8::Local<v8::Value>> results; |
| 89 m_scriptController->executeScriptInIsolatedWorld(isolatedWorldId, source
s, extensionGroup, 0); | 89 m_scriptController->executeScriptInIsolatedWorld(isolatedWorldId, source
s, extensionGroup, 0); |
| 90 pumpPendingRequestsDoNotUse(m_webViewHelper.webViewImpl()->mainFrame()); | 90 pumpPendingRequestsDoNotUse(m_webViewHelper.webViewImpl()->mainFrame()); |
| 91 } | 91 } |
| 92 | 92 |
| 93 bool verifyActivities(const String& activities) | 93 bool verifyActivities(const String& activities) |
| 94 { | 94 { |
| 95 Vector<String> activityVector; | 95 Vector<String> activityVector; |
| 96 activities.split("\n", activityVector); | 96 activities.split("\n", activityVector); |
| 97 return m_activityLogger->verifyActivities(activityVector); | 97 return m_activityLogger->verifyActivities(activityVector); |
| 98 } | 98 } |
| 99 | 99 |
| 100 private: | 100 private: |
| 101 static const int isolatedWorldId = 1; | 101 static const int isolatedWorldId = 1; |
| 102 static const int extensionGroup = 0; | 102 static const int extensionGroup = 0; |
| 103 | 103 |
| 104 WebViewHelper m_webViewHelper; | 104 WebViewHelper m_webViewHelper; |
| 105 RawPtrWillBePersistent<ScriptController> m_scriptController; | 105 Persistent<ScriptController> m_scriptController; |
| 106 // TestActivityLogger is owned by a static table within V8DOMActivityLogger | 106 // TestActivityLogger is owned by a static table within V8DOMActivityLogger |
| 107 // and should be alive as long as not overwritten. | 107 // and should be alive as long as not overwritten. |
| 108 TestActivityLogger* m_activityLogger; | 108 TestActivityLogger* m_activityLogger; |
| 109 }; | 109 }; |
| 110 | 110 |
| 111 TEST_F(ActivityLoggerTest, EventHandler) | 111 TEST_F(ActivityLoggerTest, EventHandler) |
| 112 { | 112 { |
| 113 const char* code = | 113 const char* code = |
| 114 "document.body.innerHTML = '<a onclick=\\\'do()\\\'>test</a>';" | 114 "document.body.innerHTML = '<a onclick=\\\'do()\\\'>test</a>';" |
| 115 "document.body.onchange = function(){};" | 115 "document.body.onchange = function(){};" |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 "blinkAddElement | script | data:text/html;charset=utf-8,D\n" | 522 "blinkAddElement | script | data:text/html;charset=utf-8,D\n" |
| 523 "blinkRequestResource | Script | data:text/html;charset=utf-8,D\n" | 523 "blinkRequestResource | Script | data:text/html;charset=utf-8,D\n" |
| 524 "blinkRequestResource | XMLHttpRequest | data:text/html;charset=utf-8,E"
; | 524 "blinkRequestResource | XMLHttpRequest | data:text/html;charset=utf-8,E"
; |
| 525 executeScriptInMainWorld(code); | 525 executeScriptInMainWorld(code); |
| 526 ASSERT_TRUE(verifyActivities("")); | 526 ASSERT_TRUE(verifyActivities("")); |
| 527 executeScriptInIsolatedWorld(code); | 527 executeScriptInIsolatedWorld(code); |
| 528 ASSERT_TRUE(verifyActivities(expectedActivities)); | 528 ASSERT_TRUE(verifyActivities(expectedActivities)); |
| 529 } | 529 } |
| 530 | 530 |
| 531 } // namespace blink | 531 } // namespace blink |
| OLD | NEW |