Exemplo n.º 1
0
        public void cross_agent_browser_monitor_injection_from_text()
        {
            var data     = "<html><head /><body>im some body text</body></html>";
            var expected = "<html><head />EXPECTED_RUM_LOADER_LOCATION<body>im some body text</body></html>";
            var writer   = new BrowserMonitoringWriter(() => "EXPECTED_RUM_LOADER_LOCATION");
            var result   = writer.WriteScriptHeaders(data);

            Assert.AreEqual(expected, result);
        }
Exemplo n.º 2
0
        public void empty_input_results_in_empty_output()
        {
            // ARRANGE
            string content = string.Empty;

            // ACT
            BrowserMonitoringWriter writer = new BrowserMonitoringWriter(() => _jsScript);
            string modifiedContent         = writer.WriteScriptHeaders(content);

            // ASSERT
            Assert.AreEqual(string.Empty, modifiedContent);
        }
Exemplo n.º 3
0
        public void html_with_self_closing_head_tag()
        {
            // ARRANGE
            string content  = "<html><head/><body><p>YoAdrian!</p></body></html>";
            string expected = string.Format("<html><head/>{0}<body><p>YoAdrian!</p></body></html>", _jsScript);

            // ACT
            BrowserMonitoringWriter writer = new BrowserMonitoringWriter(() => _jsScript);
            string modifiedContent         = writer.WriteScriptHeaders(content);

            // ASSERT
            Assert.AreEqual(expected, modifiedContent);
        }
Exemplo n.º 4
0
        public void html_without_head_tag_but_with_body_text_in_script()
        {
            // ARRANGE
            string content  = "<html> <body><script type=\"text/javascript\">var thing = \"<body\";</script><p>Yo Adrian!</p> </body></html>";
            string expected = string.Format("<html> {0}<body><script type=\"text/javascript\">var thing = \"<body\";</script><p>Yo Adrian!</p> </body></html>", _jsScript);

            // ACT
            BrowserMonitoringWriter writer = new BrowserMonitoringWriter(() => _jsScript);
            string modifiedContent         = writer.WriteScriptHeaders(content);

            // ASSERT
            Assert.AreEqual(expected, modifiedContent);
        }
Exemplo n.º 5
0
        public void html_with_head_tag_with_attributes()
        {
            // ARRANGE
            string content  = "<html><head bestevar='Boston Red Sox'></head><body><p>YoAdrian!</p></body></html>";
            string expected = string.Format("<html><head bestevar='Boston Red Sox'>{0}</head><body><p>YoAdrian!</p></body></html>", _jsScript);

            // ACT
            BrowserMonitoringWriter writer = new BrowserMonitoringWriter(() => _jsScript);
            string modifiedContent         = writer.WriteScriptHeaders(content);

            // ASSERT
            Assert.AreEqual(expected, modifiedContent);
        }
Exemplo n.º 6
0
        public void html_with_simple_opening_and_closing_head_tags()
        {
            // ARRANGE
            string contentUpToHead  = "<html><head>";
            string contentRemaining = "</head><body><p>YoAdrian!</p></body></html>";
            string expected         = string.Format("{0}{1}{2}", contentUpToHead, _jsScript, contentRemaining);

            // ACT
            BrowserMonitoringWriter writer = new BrowserMonitoringWriter(() => _jsScript);
            string modifiedContent         = writer.WriteScriptHeaders(contentUpToHead + contentRemaining);

            // ASSERT
            Assert.AreEqual(expected, modifiedContent);
        }
Exemplo n.º 7
0
        public void html_with_head_tag_and_X_UA_COMPATIBLE_meta_tag_with_lotta_spaces()
        {
            // ARRANGE
            string contentUpToXUATag = "<html> <head  >" +
                                       "<meta http-equiv     =              \"X-UA-Compatible\"      content=\"IE=9\">";
            string contentRemaining = "</head>        <body>  <p>    YoAdrian!</p>   </body></html>";

            string expected = string.Format("{0}{1}{2}", contentUpToXUATag, _jsScript, contentRemaining);

            // ACT
            BrowserMonitoringWriter writer = new BrowserMonitoringWriter(() => _jsScript);
            string modifiedContent         = writer.WriteScriptHeaders(contentUpToXUATag + contentRemaining);

            // ASSERT
            Assert.AreEqual(expected, modifiedContent);
        }
Exemplo n.º 8
0
        public void html_with_simple_openclose_head_tags_and_script_with_embedded_head_that_has_X_UA_COMPATIBLE_meta_tag()
        {
            // ARRANGE
            string contentUpToHead  = "<html><head>";
            string contentPartTwo   = "</head><body><p>YoAdrian!</p>";
            string contentPartThree = "<script type=\"text/javascript\">function another_head() {" +
                                      "document.write(\"<script type=\"text/javascript\"> <head><meta http-equiv=\"X-UA-Compatible\" content=\"IE=9\"></head> }" +
                                      "</script></body></html>";

            string expected = string.Format("{0}{1}{2}{3}", contentUpToHead, _jsScript, contentPartTwo, contentPartThree);

            // ACT
            BrowserMonitoringWriter writer = new BrowserMonitoringWriter(() => _jsScript);
            string modifiedContent         = writer.WriteScriptHeaders(contentUpToHead + contentPartTwo + contentPartThree);

            // ASSERT
            Assert.AreEqual(expected, modifiedContent);
        }
Exemplo n.º 9
0
        public void html_with_head_tag_X_UA_COMPATIBLE_meta_tag_and_other_head_tags()
        {
            // ARRANGE
            string contentUpToXUATag = "<html><head>" +
                                       "<meta charset=\"utf-8\" />" +
                                       "<title>Home Page - My ASP.NET MVC Application</title>" +
                                       "<link href=\"/MVC4-WebApp-Performance/favicon.ico\" rel=\"shortcut icon\" type=\"image/x-icon\" />" +
                                       "<meta name=\"viewport\" content=\"width=device-width\" />" +
                                       "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=9\">";
            string contentRemaining = "<link href=\"/MVC4-WebApp-Performance/Content/site.css\" rel=\"stylesheet\"/>" +
                                      "<script src=\"/MVC4-WebApp-Performance/Scripts/modernizr-2.6.2.js\"></script>" +
                                      "<script src=\"/mvc3_rum/Scripts/jquery-1.7.1.min.js\" type=\"text/javascript\"></script>" +
                                      "<script src=\"/mvc3_rum/Scripts/modernizr-2.5.3.js\" type=\"text/javascript\"></script>" +
                                      "</head><body><p>YoAdrian!</p></body></html>";

            string expected = string.Format("{0}{1}{2}", contentUpToXUATag, _jsScript, contentRemaining);

            // ACT
            BrowserMonitoringWriter writer = new BrowserMonitoringWriter(() => _jsScript);
            string modifiedContent         = writer.WriteScriptHeaders(contentUpToXUATag + contentRemaining);

            // ASSERT
            Assert.AreEqual(expected, modifiedContent);
        }
Exemplo n.º 10
0
 public BrowserMonitoringStreamInjector(Func <string> getJavascriptAgentScript, Stream output, Encoding contentEncoding)
 {
     _jsWriter        = new BrowserMonitoringWriter(getJavascriptAgentScript);
     OutputStream     = output;
     _contentEncoding = contentEncoding;
 }