Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <html> | 1 <html> |
| 2 <head> | 2 <head> |
| 3 <script src="../inspector-test.js"></script> | 3 <script src="../inspector-test.js"></script> |
| 4 <script src="../network-test.js"></script> | 4 <script src="../network-test.js"></script> |
| 5 <script> | 5 <script> |
| 6 function test() | 6 function test() |
| 7 { | 7 { |
| 8 function createNetworkRequest(mimeType, content) | 8 function testSearches(view, searches) |
| 9 { | 9 { |
| 10 InspectorTest.addResult("Creating a NetworkRequest with mimeType: " + mi meType); | 10 for (var search of searches) { |
| 11 var request = new WebInspector.NetworkRequest(WebInspector.targetManager .mainTarget(), 0, 'http://localhost'); | 11 view._searchInputElement.value = search; |
| 12 request.mimeType = mimeType; | 12 view._regexButton.setToggled(false); |
| 13 request._content = content; | 13 view._caseSensitiveButton.setToggled(false); |
| 14 return request; | 14 view.showSearchField(); |
| 15 InspectorTest.addResult("Should have found and highlighted all: " + search); | |
| 16 | |
| 17 var foundItems = view.element.querySelectorAll("* /deep/ .highlighte d-search-result, * /deep/ .cm-search-highlight"); | |
| 18 for (var item of foundItems) | |
| 19 InspectorTest.dumpDeepInnerHTML(item); | |
| 20 } | |
| 15 } | 21 } |
| 16 | 22 |
| 17 function getViewName(previewer) | 23 function previewViewHandled(searches, callback, view) |
| 18 { | 24 { |
| 19 if (!previewer) | 25 var isSearchable = (view instanceof WebInspector.SearchableView); |
| 20 return "** NONE **"; | 26 var compontentView = view; |
| 21 if (previewer instanceof WebInspector.SearchableView) | 27 var typeName = "unknown"; |
| 22 return "SearchableView > " + previewer._searchProvider.contentElemen t.className; | 28 if (isSearchable) |
| 23 return previewer.contentElement.className; | 29 compontentView = view._searchProvider; |
| 30 | |
| 31 if (compontentView instanceof WebInspector.ResourceSourceFrame) { | |
| 32 typeName = "ResourceSourceFrame"; | |
| 33 compontentView._ensureContentLoaded(); | |
| 34 if (!compontentView.loaded) { | |
| 35 // try again when content is loaded. | |
| 36 InspectorTest.addSniffer(compontentView, "onTextEditorContentLoa ded", previewViewHandled.bind(this, searches, callback, view)); | |
| 37 return; | |
| 38 } | |
| 39 } else if (compontentView instanceof WebInspector.XMLView) | |
| 40 typeName = "XMLView"; | |
| 41 else if(compontentView instanceof WebInspector.JSONView) | |
| 42 typeName = "JSONView"; | |
| 43 else if(compontentView instanceof WebInspector.RequestHTMLView) | |
| 44 typeName = "RequestHTMLView"; | |
| 45 else if(compontentView instanceof WebInspector.EmptyWidget) | |
| 46 typeName = "EmptyWidget"; | |
| 47 else if(compontentView instanceof WebInspector.RequestHTMLView) | |
| 48 typeName = "RequestHTMLView"; | |
| 49 | |
| 50 InspectorTest.addResult("Is Searchable: " + isSearchable); | |
| 51 InspectorTest.addResult("Type: " + typeName); | |
| 52 | |
| 53 if (isSearchable) | |
| 54 testSearches(view, searches); | |
| 55 | |
| 56 callback(); | |
| 24 } | 57 } |
| 25 | 58 function trySearches(request, searches, callback) |
| 26 function testPreviewer(request, searches) | |
| 27 { | 59 { |
| 28 return new Promise(function(done) { | 60 InspectorTest.addSniffer(WebInspector.RequestPreviewView.prototype, "_pr eviewViewHandledForTest", previewViewHandled.bind(this, searches, callback)); |
| 29 var previewView = new WebInspector.RequestPreviewView(request, new W ebInspector.RequestResponseView(request)); | 61 var networkPanel = WebInspector.panels.network; |
| 30 | 62 networkPanel._showRequest(request); |
| 31 previewView._createPreviewView(function(previewer) { | 63 var itemView = networkPanel._networkItemView; |
| 32 InspectorTest.addResult("Its previewer type: " + getViewName(pre viewer)); | 64 itemView._selectTab("preview"); |
| 33 if (previewer instanceof WebInspector.SearchableView) { | 65 } |
| 34 previewer._searchProvider._initialize(); | 66 function testType(contentType, content, searches, callback) |
| 35 InspectorTest.addResult("Inner searchable box is: " + getVie wName(previewer._searchProvider)); | 67 { |
| 36 for (var search of searches) { | 68 var url = "data:" + contentType + "," + encodeURIComponent(content); |
| 37 previewer._searchInputElement.value = search; | 69 InspectorTest.makeSimpleXHR("GET", url, true, function() { |
| 38 previewer._regexButton.setToggled(false); | 70 var request = InspectorTest.findRequestsByURLPattern(new RegExp(url. replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')))[0]; |
|
allada
2016/05/03 18:22:55
I could not figure out if we have a regex escape f
lushnikov
2016/05/04 17:00:47
String.prototype.escapeForRegExp should work
allada
2016/05/04 21:22:35
Done.
| |
| 39 previewer._caseSensitiveButton.setToggled(false); | 71 request._resourceType = WebInspector.resourceTypes.Document; |
| 40 previewer.showSearchField(); | 72 trySearches(request, searches, callback); |
| 41 InspectorTest.addResult("Should have found and highlight ed all: " + search); | |
| 42 var foundItems = previewer._searchProvider._treeOutline. _contentElement.getElementsByClassName('highlighted-search-result'); | |
| 43 for (var item of foundItems) | |
| 44 InspectorTest.dumpDeepInnerHTML(item); | |
| 45 } | |
| 46 } | |
| 47 done(); | |
| 48 }); | |
| 49 }); | 73 }); |
| 50 } | 74 } |
| 51 | |
| 52 function testType(contentType, content, searches, callback) | |
| 53 { | |
| 54 var request = createNetworkRequest(contentType, content); | |
| 55 testPreviewer(request, searches).then(callback); | |
| 56 } | |
| 57 InspectorTest.runTestSuite([ | 75 InspectorTest.runTestSuite([ |
| 58 function test1(next) | 76 function plainTextTest(next) |
| 77 { | |
| 78 testType("text/plain", "foo bar\nfoo bar", ["foo", /*"bar"*/], next) ; | |
| 79 }, | |
| 80 function jsonTest(next) | |
| 59 { | 81 { |
| 60 testType("application/json", "[533,3223]", ["533", "322"], next); | 82 testType("application/json", "[533,3223]", ["533", "322"], next); |
| 61 }, | 83 }, |
| 62 function test2(next) | 84 function jsonSpecialMimeTest(next) |
| 63 { | 85 { |
| 64 testType("application/vnd.document+json", "{foo0foo: 123}", ["foo"], next); | 86 testType("application/vnd.document+json", "{foo0foo: 123}", ["foo"], next); |
| 65 }, | 87 }, |
| 66 function test3(next) | 88 function xmlMultipleSearchTest(next) |
| 67 { | 89 { |
| 68 testType("text/xml", "<bar><foo/></bar>", ["bar"], next); | 90 testType("text/xml", "<bar><foo/></bar>", ["bar", "foo", "bar"], ne xt); |
| 69 }, | 91 }, |
| 70 function test4(next) | 92 function xmlSingleSearchTest(next) |
| 93 { | |
| 94 testType("text/xml", "<bar></bar>", ["bar"], next); | |
| 95 }, | |
| 96 function xmlCommentSearchTest(next) | |
| 97 { | |
| 98 testType("text/xml", "<bar><!-- TEST --></bar>", ["TEST", "/bar", "b ar"], next); | |
| 99 }, | |
| 100 function xmlCDATASearchTest(next) | |
| 101 { | |
| 102 testType("text/xml", "<a><![CDATA[GGG]]><g tee=\"gee\">tee</g></a>", ["GGG", "tee", "CDATA"], next); | |
| 103 }, | |
| 104 function xmlMimeTypeJsonTest(next) | |
| 71 { | 105 { |
| 72 testType("text/xml", "{foo0: 'barr', 'barr': 'fooo'}", ["fooo", "bar "], next); | 106 testType("text/xml", "{foo0: 'barr', 'barr': 'fooo'}", ["fooo", "bar "], next); |
| 73 }, | 107 } |
| 74 ]); | 108 ]); |
| 75 } | 109 } |
| 76 </script> | 110 </script> |
| 77 </head> | 111 </head> |
| 78 <body onload="runTest()"> | 112 <body onload="runTest()"> |
| 79 <p>Tests that resources with JSON MIME types are previewed with the JSON viewer. </p> | 113 <p>Tests that resources with JSON MIME types are previewed with the JSON viewer. </p> |
| 80 </body> | 114 </body> |
| 81 </html> | 115 </html> |
| OLD | NEW |