A very good demonstration of contingency table hypothesis testing is here The following is a crude approach and formatting and style issues for presentation are a matter of taste. Apologies for errors and ugliness of code. It could be generalized for hypotheses other than marginal homogeneity ("additive" in the demonstration, This demonstration provides useful template for generating expected values based on particular null hypothesis).
For an r x c contingency table with null hypothesis of marginal homogeneity here is a code:
chi[u_] := Module[{dim, dof, rs, cs, n, full, exp, chis, restbl, tbl, exptbl, pv, res}, dim = Dimensions[u]; dof = Times @@ (dim - 1); rs = Map[Plus @@ # &, u]; cs = Map[Plus @@ # &, Transpose[u]]; n = Total[Flatten[u]]; full = Append[MapThread[Append[#1, #2] &, {u, rs}], Join[cs, {n}]]; exp = Outer[Times, rs, cs]/n; chis = Total[Flatten[(u - exp)^2/exp]]; restbl = Grid[{{"Degrees of Freedom", dof}, {"Chi Square Statistic", N[chis, 3]}, {"p-value", pv}}, Alignment -> {{Left, "."}}, Frame -> All]; tbl = Grid[full, Background -> {None, None, {{{dim[[1]] + 1, dim[[1]] + 1}, {1, dim[[2]] + 1}} -> Pink, {{1, dim[[1]] + 1}, {dim[[2]] + 1, dim[[2]] + 1}} -> Pink}}]; exptbl = Grid[N[exp], Alignment -> {".", "."}]; pv = N[SurvivalFunction[ChiSquareDistribution[dof], chis]]; res = {"ChiSquareStatistic" -> N[chis, 2], "p-value" -> pv, "result" -> restbl, "table" -> tbl, "expectedtable" -> exptbl, "fullresults" -> Column[{"Data Table", tbl, "Expected Values Table", exptbl, "Hypothesis Testing", restbl}, Frame -> All, Background -> {Yellow, None, Yellow, None, Yellow, None}], "Properties" -> {"ChiSquareStatistic","p-value", "result", "table", "expectedtable", "fullresults"} }; # /. res & ] chisqt[u_, r_] := chi[u][r]
For example for table
x = {{50, 25, 15}, {25, 25, 35}, {15, 10, 35}, {10, 40, 55}}; chisqt[x, "table"] yields:

chisqt[x, "expectedtable"] yields:

chisqt[x, "result"] yields:

chisqt[x, "fullresults"] yields:

chisqt[x, "Properties"] yields:
{"ChiSquareStatistic","p-value", "result", "table", "expectedtable", "fullresults"}
0.216value, first of all? $\endgroup$DistributionFitTestis incorrect (but putting them in the correct order does not yield a correct test!). $\endgroup$