1 /*
2  * Copyright (C) 2013 Emweb bv, Herent, Belgium.
3  *
4  * See the LICENSE file for terms of use.
5  */
6 #include <boost/test/unit_test.hpp>
7 
8 #include <sstream>
9 #include <Wt/WAnchor.h>
10 #include <Wt/WImage.h>
11 #include <Wt/WText.h>
12 #include <Wt/Test/WTestEnvironment.h>
13 #include <Wt/WApplication.h>
14 
15 using namespace Wt;
16 
BOOST_AUTO_TEST_CASE(test_trampoline1)17 BOOST_AUTO_TEST_CASE(test_trampoline1)
18 {
19   Wt::Test::WTestEnvironment env;
20   env.setSessionIdInUrl(true);
21 
22   Wt::WApplication app(env);
23 
24   {
25     Wt::WText t("<div style=\"background-image: "
26 		"url(http://www.google.be)\"></div>");
27 
28     std::stringstream s;
29     t.htmlText(s);
30 
31     std::cerr << s.str() << std::endl;
32     std::size_t red = s.str().find
33       ("?request=redirect&amp;url=http%3a%2f%2fwww.google.be&amp;hash=");
34 
35     BOOST_REQUIRE(red != std::string::npos);
36   }
37 
38   {
39     Wt::WText t("<div style=\"background-image: "
40 		"url('http://www.google.be')\"></div>");
41     std::stringstream s;
42     t.htmlText(s);
43 
44     std::size_t red = s.str().find
45       ("?request=redirect&amp;url=http%3a%2f%2fwww.google.be&amp;hash=");
46 
47     BOOST_REQUIRE(red != std::string::npos);
48   }
49 
50   {
51     Wt::WText t("<div style=\"background-image: "
52 		"url('http://www.google.be')\">"
53 		"<span style=\"background-image: "
54 		"url('http://www.webtoolkit.eu')\"></span></div>");
55     std::stringstream s;
56     t.htmlText(s);
57 
58     std::size_t red = s.str().find
59       ("?request=redirect&amp;url=http%3a%2f%2fwww.google.be&amp;hash=");
60 
61     BOOST_REQUIRE(red != std::string::npos);
62 
63     red = s.str().find
64       ("?request=redirect&amp;url=http%3a%2f%2fwww.webtoolkit.eu&amp;hash=");
65 
66     BOOST_REQUIRE(red != std::string::npos);
67   }
68 
69   {
70     Wt::WImage img("http://www.google.be");
71 
72     std::stringstream s;
73     img.htmlText(s);
74 
75     std::size_t red = s.str().find
76       ("?request=redirect&amp;url=http%3a%2f%2fwww.google.be&amp;hash=");
77 
78     BOOST_REQUIRE(red != std::string::npos);
79   }
80 
81   {
82     Wt::WAnchor img("http://www.google.be");
83 
84     std::stringstream s;
85     img.htmlText(s);
86 
87     std::size_t red = s.str().find
88       ("?request=redirect&amp;url=http%3a%2f%2fwww.google.be&amp;hash=");
89 
90     BOOST_REQUIRE(red != std::string::npos);
91   }
92 
93   {
94     Wt::WContainerWidget w;
95     w.decorationStyle().setBackgroundImage("http://www.google.be");
96 
97     std::stringstream s;
98     w.htmlText(s);
99 
100     std::cerr << s.str() << std::endl;
101 
102     std::size_t red = s.str().find
103       ("?request=redirect&amp;url=http%3a%2f%2fwww.google.be&amp;hash=");
104 
105     BOOST_REQUIRE(red != std::string::npos);
106   }
107 }
108